当前位置: 首页 > 后端技术 > Python

Django2.2报错:UnicodeDecodeError解决方法

时间:2023-03-25 22:06:46 Python

Django2.2报错:UnicodeDecodeError:'gbk'codeccan'tdecodebyte0xa6inposition9737:illegalmultibytesequence1.问题重现File"D:\Python\Python37-32\lib\site-packages\django\views\debug.py",第332行,在get_traceback_htmlt=DEBUG_ENGINE.from_string(fh.read())UnicodeDecodeError:'gbk'codeccan'tdecodebyte0xa6inposition9737:illegalmultibytesequence2.解决办法打开django/views下的debug.py文件,到第331行:withPath(CURRENT_DIR,'templates','technical_500.html').open()asfh改成:withPath(CURRENT_DIR,'templates','technical_500.html').open(encoding="utf-8")asline338offhmayalsoneedtomodifyencoding.这成功解决了它。