Noob » Tutorial » UnicodeDecodeError in ‘basehttp.py’

629 views
Skip to first unread message

PureVirtual

unread,
Oct 13, 2010, 12:38:20 PM10/13/10
to Django users
Hi, Django People!

It's my second day of getting Django basics so I'm just following the
Tutorial precisely. When I first got to the admin site I noticed that
it looks odd like the page has lost it's CSS. So I tried to load the
CSS file mentioned in the header: http://127.0.0.1:8000/media/css/base.css
. What I saw was a Python Traceback cited at the and of this post. Can
you tell me what could be the cause of this problem and what should be
done to solve it? I'm running Django 1.2.3 and Python 2.7 on
Windows(sorry) XP system. The system language is English but my native
language is Russian so it can be mentioned somewhere in the system
registry and may cause some non-ASCII characters appearance in random
places.

Traceback (most recent call last):

File "C:\progs\Python27\lib\site-packages\django\core\servers
\basehttp.py", line 280, in run
self.result = application(self.environ, self.start_response)

File "C:\progs\Python27\lib\site-packages\django\core\servers
\basehttp.py", line 709, in __call__
mime_type = mimetypes.guess_type(file_path)[0]

File "C:\progs\Python27\lib\mimetypes.py", line 294, in guess_type
init()

File "C:\progs\Python27\lib\mimetypes.py", line 355, in init
db.read_windows_registry()

File "C:\progs\Python27\lib\mimetypes.py", line 260, in
read_windows_registry
for ctype in enum_types(mimedb):

File "C:\progs\Python27\lib\mimetypes.py", line 250, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position
0: ordinal not in range(128)

PureVirtual

unread,
Oct 21, 2010, 7:03:37 AM10/21/10
to Django users
For people who might have the mentioned problem here is a simple
solution (at least a workaround): rename non-ASCII keys from the
registry path "HKEY_CLASSES_ROOT\MIME\Database\Content Type" (in my
case there were three of them starting with "аудио" and "видео").
Source of solution (in Russian):
http://victor-k-development.blogspot.com/2010/07/unicodedecodeerror-django.html
P.S. This seams to be a problem of Python 2.7.

Sandro Dutra

unread,
Oct 21, 2010, 7:59:47 AM10/21/10
to django...@googlegroups.com
To use unicode characters, I put on the top of source file: -*- coding: utf-8 -*- and before any string I put an "u", like: u"My unicode string". On templates, I save the file as utf-8.

There's no workaround, only code.

2010/10/21 PureVirtual <1mi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


PureVirtual

unread,
Oct 21, 2010, 9:45:15 AM10/21/10
to Django users
Sandro,
it's obviously a good thing to do when using non-ASCII characters *in
your code*. The problem is that this exception on my system showed up
whenever the mimetypes.guess_type method was called, even if it is the
only line of cod in source file (except the import line) and there are
no non-ASCII characters in it.
P.S. As I've said before this problem turned out to belong to Python's
library itself and has nothing to do with Django.
Reply all
Reply to author
Forward
0 new messages