Python——web.py模块错误【UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xab in position 285】解决方案

问题描述

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:非法多字节序列

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Starzkg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值