Stack Overfellas!我使用Python 2.7.13与请求库,我想打印发送到网站的请求的响应:
import requests
r = requests.get("url")
print r.text
但print r.text
引发了错误:'charmap' codec can't encode character u'\u2018' in position 16311: character maps to <undefined>
我已经搜索过此错误,我得到的建议是使用r.encode
提前定义编码:
r.encode = "utf-8"
r.text.encode('utf-8', 'ignore')
但它没有帮助,r.text
引发了同样的错误。
答案 0 :(得分:2)
您是否将text
设置为新编码的文字?
text = u'\u2018'
text = text.encode('utf-8', 'ignore')
print text