string - Python DBF: 'ascii' codec can't decode byte 0xf6 in position 6: ordinal not in range(128) -
i have string containing guess you'd call "special" character (o umlaut above it) , it's throwing off dbf library using (ethan furman's python dbf library https://pypi.python.org/pypi/dbf retrieve_character() function, error on last line of function 'ascii' codec can't decode byte 0xf6 in position 6: ordinal not in range(128) ).
the code:
def retrieve_character(bytes, fielddef, memo, decoder): """ returns string in bytes fielddef[class] or fielddef[empty] """ data = bytes.tostring() if not data.strip(): cls = fielddef[empty] if cls nonetype: return none return cls(data) if fielddef[flags] & binary: return data return fielddef[class](decoder(data)[0]) #error on line
dbf files have codepage attribute. sounds has not been correctly set file. know code page used create data? if so, can override dbf's setting when open file:
table = dbf.table('dbf_file', codepage='cp437') cp437 example -- use whatever appropriate.
to see current codepage of dbf file (assuming didn't override on opening) use:
table.codepage if specify wrong codepage when open file, non-ascii data incorrect (e.g. o umlaut may end n tilde).
Comments
Post a Comment