Some of my application's libraries are depending on being able to print UTF-8 characters to stdout and stderr. Therefore this must not fail:
print('\u2122')
On my local machine it works, but on my remote server it raises UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)
I tried $ PYTHONIOENCODING=utf8
with no apparent effect.
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
works for a while, then stalls and finally fails with ValueError: underlying buffer has been detached
sys.getdefaultencoding()
returns 'utf-8'
, and sys.stdout.encoding
returns 'ANSI_X3.4-1968'
What can I do? I don't want to edit third-party libraries.