UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

django 升级后,前端输入数据信息时,后台一直报错

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

报错信息如:

File "D:\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
  response = get_response(request)
File "D:\Programs\Python\Python37\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
  response = response or self.get_response(request)
File "D:\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
  response = response_for_exception(request, exc)
File "D:\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception
  response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "D:\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception
  return debug.technical_500_response(request, *exc_info)
File "D:\Programs\Python\Python37\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
  html = reporter.get_traceback_html()
File "D:\Programs\Python\Python37\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html
  t = DEBUG_ENGINE.from_string(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

解决方法:
打开: D:\Programs\Python\Python37\lib\site-packages\django\views\debug.py 文件
定位到332行:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence_第1张图片
image.png

将标记行改为:

def get_traceback_html(self):
        """Return HTML version of debug 500 HTTP error page."""
        with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:
            t = DEBUG_ENGINE.from_string(fh.read())
        c = Context(self.get_traceback_data(), use_l10n=False)
        return t.render(c)

再次执行数据添加,成功

你可能感兴趣的:(UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence)