我对HMAC有轻微的问题.运行这段代码时:
signature = hmac.new(
key=secret_key,
msg=string_to_sign,
digestmod=sha1,
)
Run Code Online (Sandbox Code Playgroud)
我收到一个奇怪的错误:
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 72, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
Run Code Online (Sandbox Code Playgroud)
当我打印string_to_sign时,它是一个正确的字符串,如下所示:
GET
\n
\n
application/json
\n
\n
\n
Run Code Online (Sandbox Code Playgroud)
错误是什么意思?是因为新线?
小智 15
确保"key"和"msg"是一个字符串.如:
s = hmac.new(str(secretkey),str(message),digestmod = hashlib.sha1).hexdigest()
| 归档时间: |
|
| 查看次数: |
14837 次 |
| 最近记录: |