如何解决 UnicodeDecodeError, invalid continuation byte 错误
How to solve UnicodeDecodeError, invalid continuation byte error
我 运行 Python 中的一些代码并收到以下错误,使用 f = open(file) 和 f.read() 命令:
File "/usr/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 62475: invalid continuation byte
首先,如何在源文件中找到62475位置,看看是什么字符?我试过用pluma和notepadqq打开文件,都显示行号和列号,但是好像没有办法按位置号搜索。
找到问题区域后,是否有关于字符类型是什么以及如何解决问题的快速指南?
如果有帮助,您可以尝试使用 xxd -b -s +62475 <yourfilename>
在开放编码=latin-1 – Padraic Cunningham
谢谢,代码完美运行!没有错误消息,所以我认为编码实际上是 latin-1 而不是 UTF-8,所以位置 62475 的任何内容都可能没有实际意义。 – 用户 2144412
我 运行 Python 中的一些代码并收到以下错误,使用 f = open(file) 和 f.read() 命令:
File "/usr/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 62475: invalid continuation byte
首先,如何在源文件中找到62475位置,看看是什么字符?我试过用pluma和notepadqq打开文件,都显示行号和列号,但是好像没有办法按位置号搜索。
找到问题区域后,是否有关于字符类型是什么以及如何解决问题的快速指南?
如果有帮助,您可以尝试使用 xxd -b -s +62475 <yourfilename>
在开放编码=latin-1 – Padraic Cunningham
谢谢,代码完美运行!没有错误消息,所以我认为编码实际上是 latin-1 而不是 UTF-8,所以位置 62475 的任何内容都可能没有实际意义。 – 用户 2144412