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