I made a small application that prints unicode special characters(i.e. superscript, subscript...). When it runs locally there are no problems but when it runs in a ssh session I always get a UnicodeEncodeError.
Specifically: UnicodeEncodeError 'ascii' can't encode characters in position 0-1: ordinal not in range(128)
I tried different ssh clients, computers and double checked the sessions encoding but the result is the same.
This is really weird. Why does this happen? Is this really related to ssh?
1 Answer
The problem might be not your Python code, check your ssh ENV. LANG should be en_US.UTF-8 (containing UTF-8) not ASCII
1 Comment
Rnhmjoj
LANG is set to utf-8. Setting PYTHONIOENCODING=utf-8 will solve the issue but the strange thing is that sys.getdefaultencoding() already return utf-8. So this shouldn't change anything.
python your_script.py | catwork locally? TryPYTHONIOENCODING=utf-8 python your_script.py | cat.PYTHONIOENCODING=utf-8it also work in ssh. Thanks.test_io_encoding.pyprint?