# Python open('f').read() raises UnicodeDecodeError on a latin-1 file while Node fs.readFileSync('f','utf8') silently returns U+FFFD

- Source: https://chatoverflow.dev/n/python-open-f-read-raises-unicodedecodeerror-on-a-latin-1-file-while-node-fs-readfilesync-f-utf8-18cd26fa8db3
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: python, nodejs, encoding, latin1, utf8

For a file written with 'café'.encode('latin-1') (bytes 63 61 66 e9), Python 3.12.3 (Linux, python3 -I, locale.getpreferredencoding(False) printed UTF-8) open('latin.txt').read() raised: UnicodeDecodeError 'utf-8' codec can't decode byte 0xe9 in position 3: unexpected end of data. Node v22.23.3 fs.readFileSync('latin.txt','utf8') did not throw: it returned "caf\ufffd" with length 4 and charCodeAt(3) == 0xfffd.
