运行Django dev服务器时出现UnicodeDecodeError

时间:2010-11-18 11:16:36

标签: python django encoding

的UnicodeDecodeError

尝试访问站点媒体文件夹中的任何文件时出现

在调试模式下显示完整的回溯:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/site-media/img/image.png
Django Version: 1.2.3
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.markup',
 'special']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Languages\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\Languages\Python27\lib\site-packages\django\views\static.py" in serve
  59.     mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream'
File "C:\Languages\Python27\lib\mimetypes.py" in guess_type
  294.         init()
File "C:\Languages\Python27\lib\mimetypes.py" in init
  355.             db.read_windows_registry()
File "C:\Languages\Python27\lib\mimetypes.py" in read_windows_registry
  260.             for ctype in enum_types(mimedb):
File "C:\Languages\Python27\lib\mimetypes.py" in enum_types
  250.                     ctype = ctype.encode(default_encoding) # omit in 3.x!

Exception Type: UnicodeDecodeError at /site-media/img/image.png
Exception Value: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

1 个答案:

答案 0 :(得分:5)

这似乎是Python 2.7 mimetypes.py中的一个问题。请看以下讨论主题:

http://groups.google.com/group/django-users/browse_thread/thread/613909b35a7462a0

有一篇俄语文章的链接,上面写着google-translated:

  

标准库的存在   源Python - 并允许我们找到   问题很快。 Windows XP。我在用   Windows XP。   [HKEY_CLASSES_ROOT \ CLSID {4063BE15-3B08-470D-A0D5-B37161CFFD69} \ EnableFullPage \ MIME]   在我的情况下   问题是在注册表下   [HKEY_CLASSES_ROOT \ CLSID \   {4063BE15-3B08-470D-A0D5-B37161CFFD69}   \ EnableFullPage \ MIME]包含   包含名称的小节   西里尔字母。如果删除这些   键,它们是自动的   重新创建。因此有帮助   重命名,只是取代了西里尔文   拉丁文字母。

以下是文章: http://translate.google.fr/translate?js=n&prev=_t&hl=fr&ie=UTF-8&layout=2&eotf=1&sl=ru&tl=en&u=http%3A%2F%2Fvictor-k-development.blogspot.com%2F2010%2F07%2Funicodedecodeerror-django.html