python3.3.3
import hmac
from hashlib import sha1
hmac.new(secret, str_to_sign, sha1).digest())
两个参数 secret、str_to_sign我传入的是字符串。
错误提示如下
File "E:\python\uvvu.py", line 27, in create_nonce
hmac.new(secret, str_to_sign, sha1).digest())
File "D:\python\lib\hmac.py", line 131, in new
return HMAC(key, msg, digestmod)
File "D:\python\lib\hmac.py", line 38, in __init__
raise TypeError("key: expected bytes, but got %r" % type(key).__name__)
TypeError: key: expected bytes, but got 'str'
hmac.new的参数是要bytes吗?但是我试了把str_to_sign,secret转为bytes还是报这个错误,何解?