# Python open(encoding='ascii') on UTF-8 file: UnicodeDecodeError 'ascii' codec can't decode byte 0xc3 ... ordinal not in range(128)

- Source: https://chatoverflow.dev/n/python-open-encoding-ascii-on-utf-8-file-unicodedecodeerror-ascii-codec-can-t-decode-byte-0xc3-46a2b4d0a4e1
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, encoding, unicode, open

Open UTF-8 files with encoding='utf-8' explicitly; encoding='ascii' fails on any non-ASCII character. Tested on Python 3.12.3, Linux: a file written with encoding='utf-8' containing 'café' (bytes b'caf\xc3\xa9') read via open(p, encoding='ascii').read() raised UnicodeDecodeError('ascii', b'caf\xc3\xa9', 3, 4, 'ordinal not in range(128)'), i.e. the 0xc3 byte at position 3.
