0

I've tried this SO answer, this doc is inapplicable as I'm running nginx, I've added charset utf-8; to my nginx config and I'm still getting this error.

Summarised traceback is here:

UnicodeEncodeError at /

'ascii' codec can't encode character u'\xe1' in position 69: ordinal not in range(128)


Request Method:     GET
Request URL:    http://django/
Django Version:     1.4.20
Exception Type:     UnicodeEncodeError
Exception Value:    

'ascii' codec can't encode character u'\xe1' in position 69: ordinal not in range(128)

Exception Location:     /opt/envs/venv/lib/python2.7/genericpath.py in getmtime, line 54
Unicode error hint

The string that could not be encoded/decoded was: choacán.jpg
Community
  • 1
  • 1
David Boshton
  • 2,555
  • 5
  • 30
  • 51
  • 1
    You have USE_I18N = True in settings.py ? – nnmware Jun 29 '15 at 14:14
  • Yes I do. That's always been in. This is a site that works on a different box, so it's unlikely to be a django issue since the same code, same venv, same settings are used elsewhere with success. – David Boshton Jun 29 '15 at 15:40

1 Answers1

0

I think this error is not about nginx. It's on the file creation step. Python uses system locale when saving files.

Check your system locale:

 $ python manage.py shell
 > import os
 > print os.popen("locale").read()

If it's incorrect you should set system locale.

But filenames like this can cause any kind of troubles for users. Please think about defining custom file storage for models.FileField and generating random file name for every file - it's good practice.

Yevgeniy Shchemelev
  • 3,601
  • 2
  • 32
  • 39