dbfread icon indicating copy to clipboard operation
dbfread copied to clipboard

struct.error: unpack requires a bytes object of length 32

Open Crazzzme opened this issue 7 years ago • 4 comments

I am trying to open a simple dbase III file and I am getting

File "C:/Users/user/Documents/Python/SAG/dbftest.py", line 4, in <module>
    test = DBF('SystemRecord.dbf')
  File "C:\Python36-32\lib\site-packages\dbfread\dbf.py", line 122, in __init__
    self._read_field_headers(infile)
  File "C:\Python36-32\lib\site-packages\dbfread\dbf.py", line 224, in _read_field_headers
    field = DBFField.unpack(sep + infile.read(DBFField.size - 1))
  File "C:\Python36-32\lib\site-packages\dbfread\struct_parser.py", line 36, in unpack
    items = zip(self.names, self.struct.unpack(data))

struct.error: unpack requires a bytes object of length 32

Im assuming there is some field/index in my file that is larger/shorter than some maximum. Any ideas whats causing this?

Crazzzme avatar Feb 13 '18 16:02 Crazzzme

It's been a while but I ran into the same issue today. It seems like it has to do with a field issue. I changed a char field in the DBF from length 1 to 2 and then everything worked fine.

SolariaIT avatar May 18 '18 18:05 SolariaIT

I've run into this when I've had a file that ended too soon. The parser expects to read a while field but gets too few bytes.

olemb avatar Dec 21 '20 04:12 olemb

I got this error when the file was zero bytes.

jdbranham avatar Jul 01 '21 21:07 jdbranham

It could at least raise a well-defined Exception, so that we can handle it better.

fccoelho avatar Sep 12 '22 14:09 fccoelho