问题描述
render = web.template.render('templates', base='base')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\application.py", line 255, in process
return p(lambda: process(processors))
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\application.py", line 643, in processor
return handler()
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\application.py", line 255, in <lambda>
return p(lambda: process(processors))
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\application.py", line 264, in process
raise self.internalerror()
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\application.py", line 545, in internalerror
return debugerror()
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\debugerror.py", line 313, in debugerror
return web._InternalError(djangoerror())
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\debugerror.py", line 271, in djangoerror
_get_lines_from_file(filename, lineno, 7)
File "D:\ProgramData\Anaconda3\envs\chineseocr\lib\site-packages\web\debugerror.py", line 246, in _get_lines_from_file
source = open(filename).readlines()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xab in position 285: illegal multibyte sequence
问题描述
'gbk'编解码器无法解码位置257中的字节0x9a:非法多字节序列
解决方案
根据提示找到python3安装目录下的libs/site-pageages/web文件夹下template.py文件找到1016行修改如下:
return Template(open(path).read(), filename=path, **self._keywords)
修改为
return Template(open(path,encoding='utf-8').read(), filename=path, **self._keywords)
找到libs/site-pageages/web文件夹下debugerror.py文件找到246行修改如下:
source = open(filename).readlines()
修改为
source = open(filename, encoding='utf-8').readlines()
参考文章
python3 web.py模块中使用template render出错 'gbk'编解码器无法解码位置257中的字节0x9a:非法多字节序列