Tag Archives: UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa6 in position 9737: ill

[Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa6 in position 9737: ill

Django2. 2 after installation, use runserver for development. When an error occurs, the error message is only displayed on the console command line, and only one line is displayed on the front page

“A server error occurred. Please contact the administrator.”
troubleshooting is very inconvenient. Check the error information on the console carefully and give a prompt

Unicode decodeerror: ‘GBK’ codec can’t decode byte 0xa6 in position 9737: ill…
it is judged that this version of Django cannot be displayed normally due to the code reading problem of the error message code
follow the prompts to find the python installation path\lib\site_packages\Django\views\debug.Py, after it is opened, the modification is about 332 lines, which will:

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

Change to

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

That is, set the encoding, and then restart runserver. The error information can be displayed on the page normally.