简体   繁体   English

Python UnicodeDecodeError:“ utf-8”编解码器无法解码位置2的字节0x8c:无效的起始字节

[英]Python UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8c in position 2: invalid start byte

anyone know how do i decode my Hex value on Python version 3.6.0 ? 有人知道如何在Python 3.6.0版上解码我的Hex值吗?

i was using x.decode("hex") but since python update it doesn't work anymore. 我正在使用x.decode(“ hex”),但是由于python更新,它不再起作用了。

here is my hex value: 这是我的十六进制值:

 01008C647620302E31302E372070762039393130333120736E20333137337C6661336232653863206D7A20313778313720736B6620343235357C34376330643162302073706620333237397C363236373361376520627066203332363137307C61653138366364642073746620323538397C623634383035633220616D66203335333230357C633736333133626200 

In Python 3.6 there is no need to decode strings (of type str ), since they are already utf-8. 在Python 3.6中,无需解码字符串(类型为str ),因为它们已经是utf-8了。 Further, the normal decode function, allows only "standard" string decodings. 此外,正常decode功能仅允许“标准”字符串解码。 That is, this function cannot decode hex. 也就是说,此功能无法解码十六进制。

Instead, this "special" decoding functionality is moved to codecs.decode . 相反,此“特殊”解码功能已移至codecs.decode Thus, you want to rewrite your code as: 因此,您希望将代码重写为:

import codecs
x = "01008C647620302E31302E372070762039393130333120736E20333137337C6661336232653863206D7A20313778313720736B6620343235357C34376330643162302073706620333237397C363236373361376520627066203332363137307C61653138366364642073746620323538397C623634383035633220616D66203335333230357C633736333133626200"
codecs.decode(x, 'hex')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 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' 编解码器无法解码位置 3131 中的字节 0x80:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte UnicodeDecodeError:'utf-8'编解码器无法解码位置3的字节0x97:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 3: 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:'utf-8'编解码器无法解码位置0的字节0x99:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte UnicodeDecodeError'utf-8'编解码器无法解码位置2893中的字节0x92:无效的起始字节 - UnicodeDecodeError 'utf-8' codec can't decode byte 0x92 in position 2893: invalid start byte UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1551 中的字节 0x87:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 1551: invalid start byte UnicodeDecodeError:“utf-8”编解码器无法解码 position 35 中的字节 0x96:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 35: invalid start byte UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0x80:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM