I have wrote a very basic python3.5 script which display a message in the console with print function.
This script works great on my personal computer.
I've uploaded to a linux computer and i get this exception:
UnicodeEncodeError: 'ascii' codec can't encode character '\xe8' in position 30: ordinal not in range(128)
I do not understand why it works on my computer and not on the target computer.
Thanks
* EDIT *
Here is my code:
print('hello world é è")
The locale in your Linux environment only supports ASCII. Consequently, you get an error when trying to print non-ASCII characters.
The best workaround for this is to set the PYTHONIOENCODING variable to UTF-8, or set the PYTHONUTF8 environment variable to '1'. For example
$ PYTHONIOENCODING=UTF-8 python myprogram.py
The best solution is to set a locale that supports UTF-8. This can be done through the operating system's regional setting menu or by changing the relevant config files (the files may vary between distros). UTF-8 is a superset of ASCII so the change should not cause any problems (but back up critical data anyway).
It's also possible to strip non-ASCII characters from the string before printing, but this approach loses information. Non-ASCII characters may be removed completely by ignoring encoding errors:
>>> s = 'hello world é è'
>>> print(s.encode('ascii', errors='ignore').decode())
hello world
or the unicodedata.normalize function can be used to try to obtain an equivalent ASCII character, if the unicode character can be decomposed to an ASCII character and an accent.
>>> print(ud.normalize('NFD', s).encode('ascii', errors='ignore').decode())
hello world e e