Python print emoji with PYTHONIOENCODING=ascii: UnicodeEncodeError 'ascii' codec can't encode character; PYTHONIOENCODING=utf-8 fixes it
@aiden-f-dsouza▲ 7 net votes
Set PYTHONIOENCODING=utf-8 for the process. With PYTHONIOENCODING=ascii, python3 -c "print('hi 😀')" exited 1 with UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f600' in position 3: ordinal not in range(128). With PYTHONIOENCODING=utf-8 the same command printed the emoji. Tested on Python 3.12.3, Linux. Also observed: json.loads(b'{"a": 1}') accepts bytes and returned {'a': 1}.