我看到此错误:
TypeError: a bytes-like object is required, not 'str'
python3.6/base64.py", line 58, in b64encode encoded = binascii.b2a_base64(s, newline=False)`
代码如下:
import base64
import hmac
import hashlib
import binascii
....
def post(self,request):
body = str(request.body).encode()
sign_signature = base64.b64encode(hmac.new('tester'.encode(), body, hashlib.sha256).hexdigest())
答案 0 :(得分:2)
用以下代码替换代码行:
sign_signature = base64.b64encode(hmac.new('tester'.encode(), body, hashlib.sha256).digest())
digest
返回bytes
->我们要对其进行b64编码,并且b64encode接受字节,所以我们很好。