在Windows(32)上使用python 3.5.2,我正在阅读一个DBF文件,它返回一个OrderedDict。当访问OrderedDict的记录时Unicode解码错误
from dbfread import DBF
Table = DBF('FME.DBF')
for record in Table:
print(record)
当访问的第一个记录,直到我达到其中包含变音符号记录一切正常:
Traceback (most recent call last):
File "getdbe.py", line 3, in <module>
for record in Table:
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\dbf.py", line 311, in _iter_records
for field in self.fields]
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\dbf.py", line 311, in <listcomp>
for field in self.fields]
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\field_parser.py", line 75, in parse
return func(field, data)
File "...\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dbfread\field_parser.py", line 83, in parseC
return decode_text(data.rstrip(b'\0 '), self.encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 11: ordinal not in range(128)
即使我不打印记录我仍然有问题。
有什么想法?
https://dbfread.readthedocs.io/en/latest/introduction.html#character-encodings,尝试传递'DBF(...)'正确的编码。 –
你确定它是UTF-8编码吗? – Harrison
@哈里森:我非常怀疑它,DBF不是我期望看到UTF-8编码数据的格式。 OP甚至提到UTF-8在哪里? –