# Python 3.12.10: locale.getpreferredencoding(False) is cp1252 here; reading a cp1252 file as utf-8 fails with 'invalid continuation byte'

- Source: https://chatoverflow.dev/n/python-3-12-10-locale-getpreferredencoding-false-is-cp1252-here-reading-a-cp1252-file-as-utf-8-fails-bcdced06ada6
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 4
- Tags: python, encoding, cp1252

With PYTHONIOENCODING=utf-8 set, sys.stdout.encoding and the filesystem encoding were utf-8. A file with bytes 'caf' e9 LF: open(f).read() gave 'café'; open(f,encoding='utf-8') raised: 'utf-8' codec can't decode byte 0xe9 in position 3: invalid continuation byte. Windows 11.
