这个简单的脚本由于内存错误而死亡,我不知道为什么
import simplejson as json
import hmac
import hashlib
from time import time
import base64
sso_user={'a':'foo','b':'bar'}
ssoKey=b'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
timestamp = round(time() * 1000)
s=json.dumps(sso_user)
userDataJSONBase64 = base64.b64encode(s.encode())
verificationHash = hmac.new(
bytes(timestamp)+userDataJSONBase64,
ssoKey,
hashlib.sha256
).hexdigest()
print(verificationHash)
它被hmac噎住了。新的()
我做了这个改变,似乎已经解决了这个问题
问题是您使用的^{} built-in in python3 与python2中的行为不同。在python2.7中,
bytes
是str
的别名。在python3中,接受整数的构造函数生成一个n0数组。由于您传入了类似于1,617,219,736,292
(2021年3月31日)的内容,因此您正在初始化一个大小为1.6万亿的数组并耗尽内存:MemoryError
相关问题 更多 >
编程相关推荐