Django2.2 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa6 in position 9737

2021.03.10更新
window环境主机名存在不规范字符也会引起如上报错
请先确认windows主机名为纯英文 再继续尝试

以下是原文


win7
python 3.6.4
Django 2.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\wsgiref\handler
s.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\contrib\staticfiles\handlers.py", line 65, in __call__
    return self.application(environ, start_response)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\core\handlers\wsgi.py", line 141, in __call__
    response = self.get_response(request)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\core\handlers\base.py", line 75, in get_response
    response = self._middleware_chain(request)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\core\handlers\exception.py", line 36, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\core\handlers\exception.py", line 90, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), s
ys.exc_info())
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\core\handlers\exception.py", line 125, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\views\debug.py", line 94, in technical_500_response
    html = reporter.get_traceback_html()
  File "C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d
jango\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
[05/Jun/2019 11:16:30] "GET /testdb HTTP/1.1" 500 59

在这里插入图片描述

修改 django\views 下的 debug.py 第332行
C:\Users\YYYW\AppData\Local\Programs\Python\Python36\lib\site-packages\d jango\views\debug.py332

with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:

改为

with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding="utf-8") as fh:

同事338行也修改了
在这里插入图片描述
保存后正常了
在这里插入图片描述

ref :
http://copyfuture.com/blogs-details/8d078394f97cf2547d21c8506b95fcb3
https://www.cnblogs.com/loveprogramme/p/10726712.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dendysan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值