1

I have problem when i trying add pictures with not only ascii characters through admin interface.

It always seems to trying convert name of picture's file to ascii:

UnicodeEncodeError at /admin/app/subpicture/add/
        ('ascii', u'/home/celtrun/rails/alphasteel/public/media/my_media/subpictures/Zdj\u0119cia_iPhone_wrzesie\u0144_320.jpg', 68, 69, 'ordinal not in range(128)')
Request Method: POST
Django Version: 1.3
Exception Type: UnicodeEncodeError
Exception Value:    
('ascii', u'/home/celtrun/rails/alphasteel/public/media/my_media/subpictures/Zdj\u0119cia_iPhone_wrzesie\u0144_320.jpg', 68, 69, 'ordinal not in range(128)')
Exception Location: /bin/python-2.6.1/lib/python2.6/genericpath.py in exists, line 18
Python Executable:  /bin/python-2.6.1/bin/python

And:

Unicode error hint

The string that could not be encoded/decoded was: s/Zdjęcia_i

Result is that the picture that i try to save don't appear in specified repository. The picture's files are saved in this repository if its names don't have unicode characters in file's name. Has someone have any ideas to fix this?

3
  • You forgot to explain what you're doing with it. Commented May 30, 2011 at 0:13
  • It is enought clear now? Sorry if not, but all I just try to do it is save the picture file, and display it name in admin interface. Name of file has unicode characters.
    – krzyhub
    Commented May 30, 2011 at 0:23
  • Yeah, now it makes sense. But I still don't have a solution though, sorry. Commented May 30, 2011 at 0:24

2 Answers 2

4

After 2 years I'm having same problem with CentOS6.4 and Django 1.5.

While I search a solution I think that even I upload a file with special characters I may encounter problems with other applications. So I tried this. Using ASCII for files is better than using unicode names. Not every program support ığüşöçâİ or font. It may also cause font problems in websites.

0

The default Apache environment on Ubuntu/*nix doesn't allow non-ASCII file names. This leads to the rather unintuitive UnicodeEncodeError when submitting unicode filenames in a filefield/imagefield in Django admin.

Try adding this to the Apache config (/etc/apache2/envvars):

export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

And then restart the apache server.

3
  • Thanks, but in my server i have mod_passenger with file passenger_wsgi.py and no directory like "etc/apache2/envvars".
    – krzyhub
    Commented Jun 9, 2011 at 18:16
  • 2
    I've tried this approach, and doesn't seem to work as expected. I've restarted apache but I still get a unicode error when saving files with unicode chars Commented Sep 1, 2011 at 14:16
  • Could be a problem of the web server gateway. In my case it is gunicorn. They wont allow anything else but ASCII. Commented Nov 29, 2017 at 9:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.