编码错误: utf8 不能 0xab 或者 gbk 不能

win7 调用爬虫接口, 虚拟机里 访问此接口

两个用户同时访问


爬虫 读文件  写文件  需 全部设置  utf8 格式, 否则出现下边两种错误


报错:

File "C:\Users\Administrator\Desktop\spider_jiekou\taobao_comment_spider.py", line 281, in get_comment_content
    kw = f.read()

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 4: illegal multibyte sequence

# -----------------------------------------------------------------------------------------------------------------------

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 2: invalid continuation byte

解决:

with open('save_comment_keyword.txt', 'r', encoding='utf-8') as f:
    kw = f.read()
with open('save_comment_keyword.txt', 'w', encoding='utf-8') as f:
    f.write(kw)


posted @ 2018-06-23 18:09  殇夜00  阅读(16)  评论(0)    收藏  举报