简体   繁体   中英

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

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

>>> b'\x00\x01_\x97'.decode("Latin")
   '\x00\x01_\x97'
>>> type(b'\x00\x01_\x97'.decode("Latin"))
   <class 'str'>
>>> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM