Unicode troubles upon Apache + WSGI

396 views
Skip to first unread message

Viktor Burdeinyi

unread,
Mar 16, 2010, 7:09:59 AM3/16/10
to Django users
Hello, Dear community!

I'm working on django-project, that gathers the information from files
and folders. The main idea of project is follow: settings.py contains
the path to folder, afterwards the specific django view will create
the tree of DB records with names of child folder and files of parent
directory. The functionality I have completed, all work very well upon
python server (python ... runserver).

Next, I configure the Apach + WSGI on production server Ubuntu Server
9.10 for hosting project. At now the show begins. During the tree
building UnicodeDecodeError exception was raised when the filename/
foldername contains ciryllic symbols. Exception details are following:

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
92. response = callback(request, *callback_args,
**callback_kwargs)
File "/path/to/project/apps/controllers/gallery_controller.py" in sync
43. GalleryRepository.sync_albums_with_file_system()
File "/path/to/project/apps/repositories/gallery_repository.py" in
sync_albums_with_file_system
148. sync_albums_with_file_system(album, syncDateValue,
childPath, overrideExistFiles)
File "/path/to/project/apps/repositories/gallery_repository.py" in
sync_albums_with_file_system
138. childPath = os.path.join(rootFolder, childUnicode)
File "/usr/lib/python2.6/posixpath.py" in join
70. path += '/' + b

Exception Type: UnicodeDecodeError at /gallery/sync/
Exception Value: ('ascii', '/1111 - \xd0\xba\xd0\xbe\xd0\xbf
\xd0\xb8\xd1\x8f', 8, 9, 'ordinal not in range(128)')


WSGI configuration file:

# coding=utf-8

import os, sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/usr/local/lib/python2.6/dist-packages/django/')
sys.path.append('/path/to/project/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myportfolio.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


Project details:
1. All *.py files saved with UTF-8 encoding and have the first line #
coding=utf-8
2. Project I have tested on Mac OS X, Windows XP, Ubuntu Server 9.10
(production server) upon python server (python ... runserver) - all
work very well.

The issue was reproduced when the project Apach + WSGI is hosting.

I will be grateful for any suggestions.

Thanks,
Viktor Burdeinyi

Karen Tracey

unread,
Mar 16, 2010, 7:50:23 AM3/16/10
to django...@googlegroups.com
On Tue, Mar 16, 2010 at 6:09 AM, Viktor Burdeinyi <silvon.ua@gmail.com> wrote:

I'm working on django-project, that gathers the information from files
and folders. The main idea of project is follow: settings.py contains
the path to folder, afterwards the specific django view will create
the tree of DB records with names of child folder and files of parent
directory. The functionality I have completed, all work very well upon
python server (python ... runserver).

Next, I configure the Apach + WSGI on production server Ubuntu Server
9.10 for hosting project. At now the show begins. During the tree
building UnicodeDecodeError exception was raised when the filename/
foldername contains ciryllic symbols.

The default Apache setup on Ubuntu seems to include a LANG setting (C) that makes Apache incapable of dealing with file names containing non-ASCII characters. I've got:

export LANG='en_US.UTF-8'

in my /etc/apache2/envvars file that fixes this. You can use whatever language code you like, but you probably want the encoding part to be UTF-8.

You may need to install the matching language pack for whatever language you set before this will work.

Karen

Viktor Burdeinyi

unread,
Mar 16, 2010, 9:00:57 AM3/16/10
to Django users
Thank you, Karen

The issue was solved by setting export LANG="ru_RU.UTF-8" in /etc/
apache2/envvars

Viktor Burdeinyi

On 16 мар, 13:50, Karen Tracey <kmtra...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages