January 2019
Beginner
318 pages
8h 23m
English
UnicodeDecodeError occurs whenever byte strings cannot decode to Unicode code points. To avoid this exception, we can pass replace, backslashreplace, or ignore to the error argument in decode the as shown here:
>>> str = b"\xaf">>> str.decode('utf-8', 'strict') Traceback (most recent call last): File "<stdin>", line 1, in <module>UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 0: invalid start byte>>> str.decode('utf-8', "replace")'\ufffd'>>> str.decode('utf-8', "backslashreplace")'\\xaf'>>> str.decode('utf-8', "ignore")' '
Read now
Unlock full access