In the documentation at https://docs.python.org/3/library/stdtypes.html#bytes.decode
It says that errors='replace' is a valid option.... But what does it replace the invalid values WITH?
Follow the documentation to Error Handlers and it will explain that "replace" is applicable to text encodings.
Value:
'replace'
Meaning: Replace with a suitable replacement marker; Python will use the officialU+FFFDREPLACEMENT CHARACTER for the built-in codecs on decoding, and ‘?’ on encodingMeaning: Replace with a suitable replacement
U+FFFD acts as a filler for bytes that cannot be decoded. It looks like this:
b'ab\xffcd'.decode('utf-8', 'replace')
# 'ab�cd'
Without the "replace" argument, you may get a UnicodeDecodeError:
b'ab\xffcd'.decode('utf-8')
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 2: invalid start byte
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With