Python UnicodeDecodeError: 'utf-8'无法解码字节0x81
我正在尝试使用arelle来读取一个包含XBRL
文件的zip
压缩包。
我通过输入以下命令来实现:
C:\a>python arelleCmdLine.py -f C:\Python33\sec\2010\03\0000002809-0001047469-10
-002778-xbrl.zip
但是我遇到了一个UnicodeDecodeError
错误。
C:\a>python arelleCmdLine.py -f C:\Python33\sec\2010\03\0000002809-0001047469-10
-002778-xbrl.zip
[xmlSchema:syntax] Unrecoverable error: 'utf-8' codec can't decode byte 0x81 in
position 11: invalid start byte, 0000002809-0001047469-10-002778-xbrl.zip, impor
ting source element - 0000002809-0001047469-10-002778-xbrl.zip
Traceback (most recent call last):
File "C:\a\arelle\ModelDocument.py", line 131, in load
xmlDocument = etree.parse(file,parser=_parser,base_url=filepath)
File "lxml.etree.pyx", line 3239, in lxml.etree.parse (src\lxml\lxml.etree.c:6
9970)
File "parser.pxi", line 1770, in lxml.etree._parseDocument (src\lxml\lxml.etre
e.c:102272)
File "parser.pxi", line 1790, in lxml.etree._parseFilelikeDocument (src\lxml\l
xml.etree.c:102531)
File "parser.pxi", line 1685, in lxml.etree._parseDocFromFilelike (src\lxml\lx
ml.etree.c:101457)
File "parser.pxi", line 1134, in lxml.etree._BaseParser._parseDocFromFilelike
(src\lxml\lxml.etree.c:97084)
File "parser.pxi", line 582, in lxml.etree._ParserContext._handleParseResultDo
c (src\lxml\lxml.etree.c:91290)
File "parser.pxi", line 679, in lxml.etree._handleParseResult (src\lxml\lxml.e
tree.c:92441)
File "lxml.etree.pyx", line 327, in lxml.etree._ExceptionContext._raise_if_sto
red (src\lxml\lxml.etree.c:10196)
File "parser.pxi", line 373, in lxml.etree._FileReaderContext.copyToBuffer (sr
c\lxml\lxml.etree.c:89098)
File "C:\Python33\lib\codecs.py", line 301, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 11: invalid
start byte
这个问题和utf-8
编码有关,可能是某个字符的问题,但我不知道该怎么解决。我找到了一些指南,但对我解决这个问题没有帮助。
2 个回答
-2
经过快速搜索,出现问题的字节似乎是 Ctrl
键,根据unicode字节数据库的说法。因为 Ctrl
这个键只以十六进制数字的形式存在,并没有自己的字母,所以我在想 utf
在打印它时遇到了麻烦,导致了上面的错误。
-1
这个问题出现是因为程序需要读取的不是整个压缩文件,而是压缩文件里一个特定的文件(在这个例子中是实例文件夹),这个文件夹位于压缩文件的子目录里。
要访问压缩文件的目录,可以使用:
If our file inside the zip directory is 1.xml
C:\a>python arelleCmdLine.py -f C:\Python33\sec\2010\03\0000002809-0001047469-10
-002778-xbrl.zip\1.xml
结论:
上面提到的原因导致了一个错误,错误信息是 UnicodeDecodeError: 'utf-8' cant decode byte 0x81
。