运行 Django 开发服务器时出现 UnicodeDecodeError
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)
UnicodeDecodeError
Appears while trying to access any of the files from site media folder.
Full traceback presented in debug mode:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是Python 2.7 mimetypes.py 中的一个问题。请查看以下讨论主题:
http://groups.google.com/ group/django-users/browse_thread/thread/613909b35a7462a0
有一个俄罗斯文章的链接,谷歌翻译时说:
这是文章:
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
It seems to be a problem in Python 2.7 mimetypes.py. Look at the following discussion thread:
http://groups.google.com/group/django-users/browse_thread/thread/613909b35a7462a0
There is a link to a russian article which says when google-translated:
Here is the article:
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