python打开文件查询字符串时报UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 19: illegal multibyte sequence错误

 

当这样打开时报错了

lines = open(path).readlines()
open(path).close()
for line in lines:
idx1 = line.find('检测到的 SN 为:')
idx1 += len('检测到的 SN 为:')
idx2 = line.find(' 或许与您申请的SN不符,请联系技术提供方',idx1)
responsetimestr = line[idx1:idx2]
rts = responsetimestr
 

UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 19: illegal multibyte sequence

 

改为以下即可

lines = open(path,mode='r',encoding='UTF-8').readlines()

 

posted on 2017-07-14 17:04  Zing_Z  阅读(470)  评论(0编辑  收藏  举报

导航