Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python md5无法解码字节_Python_Python 3.x_Md5_Url Encoding_Hashlib - Fatal编程技术网

Python md5无法解码字节

Python md5无法解码字节,python,python-3.x,md5,url-encoding,hashlib,Python,Python 3.x,Md5,Url Encoding,Hashlib,我正在尝试使用hashlib库调用python3中的服务。此代码的最后一行引发异常: auth=hashed.digest().decode(“utf-8”).rstrip(“\n”) UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0x96:无效的开始字节 以下是代码片段: import hashlib m = hashlib.md5() m.update("".encode("utf-8")) data_hash = base64.b64encode(m.

我正在尝试使用
hashlib
库调用
python3
中的服务。此代码的最后一行引发异常:

auth=hashed.digest().decode(“utf-8”).rstrip(“\n”)
UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0x96:无效的开始字节
以下是代码片段:

import hashlib
m = hashlib.md5()
m.update("".encode("utf-8"))
data_hash = base64.b64encode(m.digest()).decode("utf-8")

# Create Authorization Header
canonical = '%s,application/vnd.api+json,%s,%s,%s' % (action, data_hash, url, format_date_time(stamp))
canonical = canonical.encode("utf-8")

hashed = hmac.new(bytearray(secret, "utf-8"), canonical, sha1)
auth = hashed.digest().decode("utf-8").rstrip('\n')
我遗漏了什么?

hash.digest().decode(“utf-8”).rstrip('\n')

摘要返回字节,但没有任何字节序列是有效的UTF-8


我不知道你想实现什么,但这段代码有缺陷。

你希望摘要是UTF-8编码的吗?…或者用不同的措辞,是什么让你希望摘要是UTF-8编码的?