Python unicodeescape codec can't decode bytes
发布时间
阅读量:
阅读量
编码解码异常处理
情景再现与背景构建
在利用 requests 实现登录模拟时,从网页中获取的 cookie 数据中包含了若干特殊字符
cookie = 'xxxxxxxxxxx' # 其中出现了特殊字符
headers = {
'cookie': cookie,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'host': 'www.zhihu.com'
}
res = requests.get('https://www.zhihu.com', headers=headers)
print(res.text)
1. 问题原因
在Python文件中,所采用的编码方式为UTF-8,而复制过来的cookie内容中包含需要转义处理的特殊字符。因此,在Python
全部评论 (0)
还没有任何评论哟~
