If you are having a problem getting unicode files uploaded to Apache and are getting os.path.exist exceptions in Django, you should take a look at this link:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
It is not only for mod python; I had this problem with mod_wsgi.
One of my projects at work is maintaining a Japanese language ticketing system in Django. Recently, we added additional file uploading systems and everything working, I put it live.
Unfortunately: no one could upload files with Japanese characters in the name.
My first break came from copy/pasting the error code; it was the same as the one at this Stack Overflow. It was failing on some kind of python internal operation. However, this solution did not work for me (setting the language variable) as the language variable was already us.utf-8. Furthermore, I wasn’t going to hack around in the django internals without reason.
I realized that there was probably something going on in Apache and was busy trying to find out how to switch to the Apache user in Ubuntu when the next clue came up: a Japanese message board conversation.
The important conversation is reproduced below:
:909[sage]:2010/10/14(木) 04:18:32 ID:???
解決ã—ã¾ã—ãŸã€‚
(I solved it)
åŽŸå› ã¯apache2ctl gracefulã˜ã‚ƒãªã/etc/init.d/apache2 restartã¨ã—ãªã„ã¨envvarsを変更ã—ã¦ã‚‚æ„味ãŒãªã„ã®ã‚’知らãªã„事ã§ã—ãŸã€‚
(I had to reboot directly using /etc/init.d as opposed to using apache2ctl in order to reset envars.)
webã§é›†ã‚ãŸæƒ…å ±ã‚’ã¾ã¨ã‚ã¦ãŠãã¾ã™ã€‚
(Enclosed is the information I found on the web)
1. envvars変ãˆã‚‹ã€‚
(Switch Envvars)
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
2. ãれã§ã‚‚é§„ç›®ãªã‚‰aptã§å…¥ã‚‹langage-packçš„ãªç‰©ãŒå…¥ã£ã¦ã„ã¦UTF-8ãŒä½¿ãˆã‚‹ã‹èª¿ã¹ã‚‹
ã‚ã¨ã€é–“é•ã£ãŸæƒ…å ±ã ã¨æ€ã†ã‚“ã§ã™ãŒ
3. sitecustomize.pyを用æ„ã€ã‚‚ã—ãã¯site.pyã‚’ç›´æŽ¥æ›¸ãæ›ãˆã¦ã€sys.getdefaultencoding() => ‘utf-8′ãŒå¾—られる様ã«ã™ã‚‹ã€‚
ç‰ã®æƒ…å ±ã‚’è¦‹ã¤ã‘ã¾ã—ãŸã€‚
3ã«é–¢ã—ã¦ã¯ã€sys.getdefaultencoding() => ‘ascii’ã®ã¾ã¾ã§ã‚‚僕ã¯å¤§ä¸ˆå¤«ã§ã—ãŸã€‚
返信ãã‚ŒãŸæ–¹ã€ã‚りãŒã¨ã†ã”ã–ã„ã¾ã—ãŸã€‚
The first line solved my problem. If you need a translation of the rest, let me know and I’ll be happy to do it.