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

时间:2023-01-05 09:24:18
Traceback (most recent call last):
  File "/Users/c2apple/PycharmProjects/easyToPython/fileMethod.py", line 94, in <module>
    line=fp.readline()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 99: invalid continuation byte

出现这种情况是由于读取后进行转码出现错误,遇到了非法字符,解决的方法是检测读取的文件编码,再进行下一步转码形式处理