I am attempting to upload a picture file in django admin inlines and becoming UnicodeEncodeError when attemping to upload personal files having a filename that contains non-ascii figures:

 File "/usr/local/lib/python2.6/site-packages/django/db/models/fields/files.py", line 92, in save
   self.name = self.storage.save(name, content)

 File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 47, in save
   name = self.get_available_name(name)

 File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 73, in get_available_name
   while self.exists(name):

 File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 196, in exists
   return os.path.exists(self.path(name))

 File "/usr/local/lib/python2.6/genericpath.py", line 18, in exists
   st = os.stat(path)

There's a paragraph relating to this problem in Django paperwork: http://paperwork.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror - they are saying I have to define LANG and LC_ALL env variables, plus determining them using os.env will not work. So I have defined them during my .htaccess file and I am sure they're there:

META
Variable    Value
CONTENT_LENGTH  '27289'
...
LANG    'en_US.UTF-8'
LC_ALL  'en_US.UTF-8'
LC_LANG     'en_US.UTF-8'

The issue still is available. Django version is 1.2.3 (latest stable), sys.getfilesystemencoding() (that we believe is pertinent towards the problem) returns "ANSI_X3.4-1968".

The model/admin code is certainly not special: an ArticleImage model with ImageField, and ArticleAdmin that contains ArticleImage inlines.

UPDATE I could not fix this problem so I have quit using apache setup and began the applying using runfcgi + nginx. Uploads work fine now but I am not adding this like a solution since the question involved apache.

You should attempt determining the LANG and LC_ALL for the entire Apache 2 atmosphere.

For my deployments I additionally make certain the python default system encoding is placed to utf-8 too.

For that Python default encoding It's my job to create/edit sitecustomize.py, see http://blog.ianbicking.org/imaginary-setdefaultencoding.html

For Apache - there's line in init script /etc/init.d/apache2 (Ubuntu 8.04 LTS) that produces the atmosphere. I added the right LC_ALL, LANG there. Essentially it ought to be within the server init scripts somewhere for the OSes.

On Debian (Lenny) you just add the next two lines to /etc/apache2/envvars:

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

...that's for United kingdom web servers. For All Of Us:

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

And restart Apache.