Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django uses ANSI_X3.4-1968 encoding instead of UTF-8

I'm running Ubuntu 14.04 server with Django + Gunicorn + Nginx.

Nginx config contains line for utf-8 charset.

Locale output for user "auction" (this user runs the server):

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=en_US.utf8

Filesystem encoding for this user:

sys.getfilesystemencoding()
'UTF-8'

But when I'm calling the same method in the view, it returns 'ANSI_X3.4-1968'.

So, I can not upload the files with non-latin filenames.

I've spent few days googling the solutions, nothing helps.

How to fix it?

like image 405
artem Avatar asked May 16 '16 04:05

artem


People also ask

How to fix the encoding problem of a test file?

For some encoding problem, it's better to fix on the file's side rather than the environment, as the test should be machine-independent. If by any chance, we have to configure the environment. I would suggest putting the configuration code into your build script, so that it could be run successfully everywhere.

What is the file system encoding in confluence?

The filesystem encoding in Confluence has been set to ANSI_X3.4-1968. This encoding can cause issues in Confluence as the encoding supported in Confluence is only UTF-8 (If you are running an old Confluence's version, you might need to use the parameter below instead of the CATALINA_OPTS variable:)

Why is the Catalina_opts encoding not working in confluence?

This encoding can cause issues in Confluence as the encoding supported in Confluence is only UTF-8 (If you are running an old Confluence's version, you might need to use the parameter below instead of the CATALINA_OPTS variable:) In Redhat 6.x (RPM-Based distributions), set the LANG and LC_ALL values in /etc/sysconfig/i18n as follows:


1 Answers

This sounds like you are running into bug # 13643.

The easiest way to resolve this issue is to set the environment variable PYTHONIOENCODING to utf-8.

If you are using a virtual environment, make sure you set it up explicitly in the virtual environment; as it may not read the global variables.

like image 51
Burhan Khalid Avatar answered Sep 23 '22 04:09

Burhan Khalid