运行 Django 开发服务器时出现 UnicodeDecodeError

发布于 2024-10-03 07:15:41 字数 1590 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-10-10 07:15:41

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

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

有一个俄罗斯文章的链接,谷歌翻译时说:

标准库的存在
源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

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:

The presence of the standard library
source Python-and allowed us to find
the problem pretty quickly. Windows XP. I am using
Windows XP.
[HKEY_CLASSES_ROOT\CLSID{4063BE15-3B08-470D-A0D5-B37161CFFD69}\EnableFullPage\MIME]
In my case the
problem was that in the registry under
[HKEY_CLASSES_ROOT \ CLSID \
{4063BE15-3B08-470D-A0D5-B37161CFFD69}
\ EnableFullPage \ MIME] contain
subsections containing the name of the
Cyrillic alphabet. If you delete these
keys, they are automatically
re-create. Therefore helped
to rename, just replaced the Cyrillic
alphabet in Latin.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文