UnicodeDecodeError: ‘GBK’ codec can’t decode byte 0xa6 in position 9737: Illegal multibyte sequence UnicodeDecodeError: ‘GBK’ codec can’t decode byte 0xa6 in position 9737: Illegal multibyte sequence

First, the recurrence of problems

File “D:\Python\Python37-32\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
Copy the code

Second, solutions

Open the debug.py file in django/views and go to line331:

with Path(CURRENT_DIR, 'templates'.'technical_500.html').open(a)as fh
Copy the code

Change it to:

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

The encoding may also need to be modified at the same location on line 338.

So that’s a good solution.