1.首先谈一下如何遇到这个问题的。本人想打印一个html页面,这个页面是charset 是utf-8的,按照正常方法html = response.content.decode(“utf-8”),却总是报错UnicodeEncodeError
,如果页面是gb2312的,又不错。
2.解决方法,代码段中加入
type = sys.getfilesystemencoding()
html = response.content.decode(‘utf-8’).encode(type)
相关文章
- UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position
- cx_oracle 执行cur.execute(sql)提交数据出现 UnicodeEncodeError: 'ascii' codec can't encode character u'\u2122' in position 170
- UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 1: surrogates not allowed根本解决方法
- python3 UnicodeEncodeError: 'gbk' codec can't encode character '\uff70' in position 75267: illegal multibyte sequence
- Python Solve UnicodeEncodeError 'gbk' / 'ascii' / 'utf8' codec can't encode character '\x??' in position ? 解决有关Python编码的错误
- python基础===解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转载)
- UnicodeEncodeError: 'gbk' codec can't encode character '\u200b' in position 0: illegal multibyte seq
- UnicodeEncodeError: 'ascii' codec can't encode character u'\u6211' in position 0: ordinal not in range(128)
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 0: illegal multibyte seque
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 30633: illegal multibyte sequence