美文网首页
Python3中UnicodeEncodeError: 'gbk

Python3中UnicodeEncodeError: 'gbk

作者: 奥巴牛叔 | 来源:发表于2018-06-06 22:42 被阅读0次

我用Sublime Text编写一个网络小程序时遇到UnicodeEncodeError: 'gbk' codec can't encode character错误,

很明显,这是编码的问题,requests返回的是utf-8编码,Sublime Text终端不能正常显示,通过如下设置,显示正常。

import requests

import sys

import io

sys.stdout = io.TextIOWrapper( sys.stdout.buffer, encoding='gb18030')  # 改变系统输出编码方式

然后再print(rhtml.text)就正常显示了。

相关文章

网友评论

      本文标题:Python3中UnicodeEncodeError: 'gbk

      本文链接:https://www.haomeiwen.com/subject/canisftx.html