字节消息参数错误 [英] Bytes message argument error
本文介绍了字节消息参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想不出什么'字节'方法是抱怨。在下面的code,我想为我的客户端身份验证密钥,我不断收到此错误[1]
进口HMAC
进口hashlib
进口的base64消息=字节(信息,UTF-8)在这里#错误
秘密=字节(秘密,UTF-8)签名= base64.b64en code(hmac.new(秘密,消息,digestmod = hashlib.sha256).digest());
打印(签字)
[1]
回溯(最后最近一次调用):
文件API /测试/ auth-client.py,11号线,上述<&模块GT;
消息=字节(信息,UTF-8)
类型错误:STR()采用最多1参数(2给出)
解决方案
字节()
在Python 2.x是一样的 STR( )
,它接受一个字符串参数。
使用刚消息=消息
和 =秘密的秘密
。你甚至不需要字节()
在这里。
I can't figure out what the 'bytes' method is complaining about. In the code below, i am trying to generate an authentication key for my client and i keep getting this error [1]
import hmac
import hashlib
import base64
message = bytes("Message", 'utf-8') # errors here
secret = bytes("secret", 'utf-8')
signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest());
print(signature)
[1]
Traceback (most recent call last):
File "API/test/auth-client.py", line 11, in <module>
message = bytes("Message", 'utf-8')
TypeError: str() takes at most 1 argument (2 given)
解决方案
bytes()
in Python 2.x is the same as str()
and it accepts only one string argument.
Use just message = "Message"
and secret = "secret"
. You don't even need bytes()
here.
这篇关于字节消息参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文