UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte

UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte
文章图片

上面这段代码会报:UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte sequence
UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte
文章图片

错误的原因是with没有指定编码格式。指定为utf-8格式就好了。

with open('header.html', "w", encoding="utf-8")as f:

【UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte】

    推荐阅读