When uploading files with non-ASCII characters I get UnicodeEncodeError:
Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/
Exception Value: \
Just building on answers from this thread and others...
I had the same issue with genericpath.py giving a UnicodeEncodeError when attempting to upload a file name with non ASCII characters.
I was using nginx, uwsgi and django with python 2.7.
Everything was working OK locally but not on the server
Here are the steps I took 1. added to /etc/nginx/nginx.conf (did not fix the problem)
http {
charset utf-8;
}
I added this line to etc/default/locale (did not fix the problem)
LANGUAGE="en_US.UTF-8"
I followed the instructions here listed under the heading 'Success' https://code.djangoproject.com/wiki/ExpectedTestFailures (did not fix the problem)
aptitude install language-pack-en-base
Found across this ticket https://code.djangoproject.com/ticket/17816 which suggested testing a view on the server to what was happening with locale information
In your view
import locale
locales = "Current locale: %s %s -- Default locale: %s %s" % (locale.getlocale() + locale.getdefaultlocale())
In your template
{{ locales }}
For me, the issue was that I had no locale and no default locale on my Ubuntu server (though I did have them on my local OSX dev machine) then files with non ASCII file names/paths will not upload correctly with python raising a UnicodeEncodeError, but only on the production server.
Solution
I added this to both my site and my site admin uwsgi config files e.g. /etc/uwsgi-emperor/vassals/my-site-config-ini file
env = LANG=en_US.utf8