I have a Django 1.8 app running on a server with Python 3 and I get a UnicodeDecodeError when logging and printing strings with special characters.
>:python --version
python 3.4.3
For example, if I try to run a silly method in the shell:
def print_test():
print('Test: èè') # any 'special char' like ä ç é û...
I get a stack trace:
>>> print_test()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/sailingadmin/sailing-admin/utest.py", line 2, in print_test
print('This is a test: \xe8\xe8')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-17: ordinal not in range(128)
Same with print(u'Test: èè')
Why does this error happen?
utest.py is encoded in utf-8 (Python 3 default for source files)
>:echo $LC_CTYPE
UTF-8
All logging and printing raises a UnicodeEncodeError...