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

时间:2021-11-24 00:11:52

I was running https://github.com/tianyu0915/pythoner.net/ on my MacBookPro for learning django.

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

After done as the read me says, when I ran the app, the console says:

按照我的说法完成后,当我运行应用程序时,控制台说:

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 个解决方案

#1


1  

The problem is probably this template file. It's not utf-8 (seems GB2312), but the template engine tries to decode it as such, therefore causing an error.

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

Convert it to utf-8 and you should be good - at least for this part of the problem. Next step would be to find out what caused the server error in the first place.

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

Maybe you should also file a bug report on github.

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

#1


1  

The problem is probably this template file. It's not utf-8 (seems GB2312), but the template engine tries to decode it as such, therefore causing an error.

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

Convert it to utf-8 and you should be good - at least for this part of the problem. Next step would be to find out what caused the server error in the first place.

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

Maybe you should also file a bug report on github.

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