env. settings causing UnicodeEncodeError?

21 views
Skip to first unread message

Aljoša Mohorović

unread,
Nov 15, 2010, 7:58:14 AM11/15/10
to mod...@googlegroups.com
when uploading files with non-ascii chars using a django app running
on apache/mod_wsgi i get this error:
--------
File "/var/www/wsgi/[...]/env/lib/python2.6/site-packages/django/core/files/storage.py",
line 198, in exists
return os.path.exists(self.path(name))

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

UnicodeEncodeError: 'ascii' codec can't encode characters in position
58-62: ordinal not in range(128)
--------
although it's working as expected when running locally with django
runserver command.

i think it could possibly be related with some env. setting LANG,
LC_ALL or something similar but can't figure out what exactly is
causing this.
any tips/ideas?
is it possible to configure apache/mod_wsgi to use different system
settings for LANG, LC_ALL and similar?

Aljosa Mohorovic

Aljoša Mohorović

unread,
Nov 15, 2010, 2:35:14 PM11/15/10
to mod...@googlegroups.com
adding this:
---------------------------------------------------
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
---------------------------------------------------
to /etc/apache2/envvars fixes my problem.

related question, i'm just curious, wouldn't it be better to assume
LANG=[SOME_LOCALE].UTF-8 instead of LANG=C?

Aljosa

Graham Dumpleton

unread,
Nov 15, 2010, 10:16:16 PM11/15/10
to mod...@googlegroups.com

This is an operating system Apache configuration issue. Normally an
operating system does have language and locale set to refer to UTF-8
as the defaults, but for whatever reason some Linux operating systems
override this just for Apache and reset it back to what you are
seeing.

Although you can override it in the envvars file, I believe that there
may be an actual configuration file in /etc or init startup scripts
which can override this for Apache.

If you are using a self installed Apache, obviously that wouldn't
apply, unless creating your on /etc init script and it is init system
that is doing this for all services.

Graham

Reply all
Reply to author
Forward
0 new messages