UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence

代码

text = response.content.decode(encoding="utf-8")出现报错
提示UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence
试过加ignore:
text = response.content.decode(encoding='gbk', errors='ignore')
依然报错,百度查询到了解决方案:
response.content.decode(encoding="utf-8-sig")
这样就没问题了。
posted @ 2019-02-28 13:22  薇薇前进  阅读(9584)  评论(0编辑  收藏  举报