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.py
第332
行
将
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