字节消息参数错误

编程入门 行业动态 更新时间:2024-10-28 00:29:33
本文介绍了字节消息参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想不出什么'字节'方法是抱怨。在下面的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.

更多推荐

字节消息参数错误

本文发布于:2023-10-17 22:20:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   错误   参数   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!