UnicodeDecodeError:'utf8'编解码器无法解码位置98中的字节0xb4:无效的起始字节

时间:2013-09-26 14:07:31

标签: python django macos unicode utf-8

我在MacBookPro上运行https://github.com/tianyu0915/pythoner.net/以学习django。

完成阅读后我说,当我运行应用程序时,控制台说:

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/template/loader.py", line 134, in find_template
    source, display_name = loader(name, dirs)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/template/loader.py", line 42, in __call__
    return self.load_template(template_name, template_dirs)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/template/loader.py", line 45, in load_template
    source, display_name = self.load_template_source(template_name, template_dirs)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/site-packages/django/template/loaders/filesystem.py", line 39, in load_template_source
    return (file.read().decode(settings.FILE_CHARSET), filepath)
  File "/Users/keviswang/.virtualenvs/pythoner/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position 98: invalid start byte

1 个答案:

答案 0 :(得分:1)

问题可能是this template file。它不是utf-8(似乎是GB2312),但模板引擎会尝试对其进行解码,从而导致错误。

将其转换为utf-8并且你应该很好 - 至少对于这部分问题。下一步是找出导致服务器错误的原因。

也许您还应该在github上提交错误报告。