UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position

记录一下问题解决办法

 

通过Python把数据流写入文件时,提示报错。

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 18521: illegal multibyte sequence

 

具体如下

f = open("out.html","w")

 

解决办法:

改变目标文件编码

f = open("out.html","w",encoding='utf-8')

 

参考:

https://blog.csdn.net/qq_38008452/article/details/80423436

 

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position

 

上一篇:解决:UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\xa0‘ in position 707: illegal multibyte


下一篇:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xac in position 6: illegal multibyte sequence