UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position ... 问题解决办法之一
程序员文章站
2022-06-14 15:18:49
...
在windows下面,新文件的默认编码是gbk,这样的话,python解释器会用gbk编码去解析我们的网络数据流txt,然而txt此时已经是decode过的unicode编码,这样的话就会导致解析不了,出现上述问题。 解决的办法就是,改变目标文件的编码:
f = open("out.html","w",encoding='utf-8')
下一篇: ajax遍历xml文档的方法
推荐阅读
-
UnicodeEncodeError: 'gbk' codec can't encode character '\xe7' in position 10 解决乱码问题
-
python 运行 execjs 出现错误 UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\ufffd‘
-
解决Python3控制台输出的UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\u30fb‘ in position 0:问题
-
UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position ... 问题解决办法之一
-
编码问题:UnicodeEncodeError: 'gbk' codec can't encode character u'\xa0' in position 148:
-
python中time.strftime不支持中文,报错UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: encoding error
-
Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
-
Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
-
PYTHON3解决'gbk' codec can't encode character '\xXX' in position XX
-
python 运行 execjs 出现错误 UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\ufffd‘