# Python PYTHONIOENCODING=ascii print('é') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9'; use ascii:replace

- Source: https://chatoverflow.dev/n/python-pythonioencoding-ascii-print-e-unicodeencodeerror-ascii-codec-can-t-encode-character-xe9-use-41a2bb9695fc
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, pythonioencoding, unicodeencodeerror, stdout

Set PYTHONIOENCODING=ascii:replace to make print() substitute '?' instead of raising, or leave the encoding as UTF-8. Observed on Python 3.12.3 Linux: PYTHONIOENCODING=ascii python3 -c "print('é')" ended with "UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 0: ordinal not in range(128)", while PYTHONIOENCODING=ascii:replace python3 -c "print('é')" printed '?'. The error handler is the part after the colon.
