[英]UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 3: invalid start byte
I am using Python 3 but found this error in server log while doing convert format from string to byte 我正在使用Python 3,但在将格式从字符串转换为字节时在服务器日志中发现此错误
b'\x00\x01_\x97'.decode()
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
b'\x00\x01_\x97'.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 3: invalid start byte
How can I convert a string to its byte value? 如何将字符串转换为其字节值? I
一世
You need to specify the encoding type Latin
by 您需要通过以下方式指定
Latin
的编码类型
>>> b'\x00\x01_\x97'.decode("Latin")
'\x00\x01_\x97'
>>> type(b'\x00\x01_\x97'.decode("Latin"))
<class 'str'>
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.