简体   繁体   English

UnicodeDecodeError:'utf-8'编解码器无法解码位置3的字节0x97:无效的起始字节

[英]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.

相关问题 &#39;utf-8&#39;编解码器无法解码位置14的字节0x97:无效的起始字节 - 'utf-8' codec can't decode byte 0x97 in position 14: invalid start byte UnicodeDecodeError: &#39;utf-8&#39; 编解码器无法解码位置 3131 中的字节 0x80:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte Python UnicodeDecodeError:“ utf-8”编解码器无法解码位置2的字节0x8c:无效的起始字节 - Python UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8c in position 2: invalid start byte `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte` - `UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte` UnicodeDecodeError:“utf-8”编解码器无法解码 position 76 中的字节 0x81:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 76: invalid start byte UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置0的字节0x99:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte UnicodeDecodeError&#39;utf-8&#39;编解码器无法解码位置2893中的字节0x92:无效的起始字节 - UnicodeDecodeError 'utf-8' codec can't decode byte 0x92 in position 2893: invalid start byte UnicodeDecodeError: &#39;utf-8&#39; 编解码器无法解码位置 1551 中的字节 0x87:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 1551: invalid start byte Python:UnicodeDecodeError:'utf-8'编解码器无法解码 position 中的字节 0x80 0:无效起始字节 - Python: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError:“utf-8”编解码器无法解码 position 35 中的字节 0x96:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 35: invalid start byte
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM