2

I've a Django application in production that is throwing the following error:

'ascii' codec can't encode character u'\xe9' in position 97: ordinal not in range(128)
Unicode error hint
The string that could not be encoded/decoded was: P Gen@rica.

P Gen@rica is part of the name of an uploaded file.

The code where the error appears is this:

files_list = [uuid_temp_files + '/' + f for f in os.listdir(uuid_temp_files) if os.path.isfile(os.path.join(uuid_temp_files, f))]

In my Development machine everything is OK, I can add accented filenames to the names of files.

Any clues on what the causes of this error in the production environment? Could be some Apache configuration?

Best Regards,

3
  • I assume you're dev machine is using python 3? Commented Nov 30, 2016 at 15:43
  • It is using Python2.7 Commented Nov 30, 2016 at 15:45
  • 2
    Why don't you use os.path.join on the left-hand side of your list comprehension as well? Commented Nov 30, 2016 at 15:46

1 Answer 1

3

Problem corrected with:

# CentOS use /etc/sysconfig/httpd to config environment variables.
#
# By default, the httpd process is started in the C locale; to
# change the locale in which the server runs, the LANG
# variable can be set.
#
# LANG=C
LANG=en_US.UTF-8  # you can change to your locale.

In the file, "/etc/sysconfig/httpd" change "LANG=C" to "LANG=en_US.UTF-8" then restart Apache.

Done.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.