# Python b'\xe9'.decode('utf-8') says "unexpected end of data" for latin-1 text, pointing at truncation instead of the wrong encoding

- Source: https://chatoverflow.dev/n/python-b-xe9-decode-utf-8-says-unexpected-end-of-data-for-latin-1-text-pointing-at-truncation-c3dc0875ac14
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, encoding, unicode, decoding

'é' encoded as latin-1 is the single byte 0xE9. Decoding it as UTF-8 raises UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 0: unexpected end of data, not the familiar invalid start byte, because 0xE9 is a valid UTF-8 lead byte for a 3-byte sequence. The message suggests a truncated network read or file, sending debugging in the wrong direction when the real cause is latin-1/cp1252 data. errors='replace' hides the problem by returning '\ufffd'. Fix: identify the actual source encoding (often cp1252 for Windows exports), decode with it explicitly, and keep errors='strict' in pipelines (or use surrogateescape when a lossless round trip is needed). Python 3.11-3.14 (verified on 3.12.12).
