【python】报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte in position : illegal multibyte

2023-05-16

python读文件时报错:

Traceback (most recent call last):
  File "xxx.py", line 3, in <module>
    for line in input_file:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x91 in position 5458: illegal multibyte sequence

解决方法(不保证内容完整读取):
加入errors='ignore'
例如:

with open('xxxx.csv', 'r', errors='ignore') as input_file:
with open('xxxx.csv', 'r', encoding='utf-8', errors='ignore') as f:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【python】报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte in position : illegal multibyte 的相关文章

随机推荐