UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

问题:

当访问django项目,出现这样的界面:

A server error occurred.  Please contact the administrator.

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence_第1张图片

pycharm异常:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

 

原因:

window控制台默认gbk编码,而我们通常用的是utf8

 

解决:

打开django/views下的debug.py文件,转到line331行:

   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

就成功了。

 

解决思路:

解决方法完全是依照异常信息来的。

你可能感兴趣的:(UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence)