simpledbf icon indicating copy to clipboard operation
simpledbf copied to clipboard

Dbf5('file.dbf') AssertionError assert terminator == b'\r

Open AndreMikulec opened this issue 8 years ago • 12 comments

Whenever I try to load a .dbf file I am getting an error.

>>> Dbf5('myfile.dbf')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\TARGET\WinPython-64bit-3.3.5.9\python-3.3.5.amd64\lib\site-packages\simpledbf\simpledbf.py", line 557, in __init__
    assert terminator == b'\r'
AssertionError
>>>

I am using

simpledbf-0.2.6.tar.gz

on

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32

Thanks, Andre Mikulec

AndreMikulec avatar Sep 04 '16 03:09 AndreMikulec

I'm having the same problem. Is there any plans on addressing this issue?

jdovi avatar Oct 21 '16 14:10 jdovi

I too have this problem with a file edited with the DBF Explorer.

daren-thomas avatar Mar 23 '17 15:03 daren-thomas

Any update on this?

melanatech avatar Apr 26 '17 19:04 melanatech

I have discovered that this is caused by unsupported column types: Date/Time (Timestamp), and Memo by trial and error, i.e. removing columns and a little debuggin in simpledbf.py

vanboom avatar Dec 26 '17 18:12 vanboom

My guess is that the assertion errors are a result of incorrect DBF file versions. There is a section in the README that explains which DBF versions are acceptable.

Have a look at the table entitled "Database file header" on the dbf Wikipedia page. The very last byte of the header should be 0x0D, which is is a carriage return. If that is not true, then you might have a different file version. For example in DBF version 7, the header has a much different length, so this code will not process it correctly.

You can check the DBF version info from the first byte of your file as follows:

f = open('my.dbf', 'rb')
f.read(1)

Convert this hex value into binary. As per the DBF7 description, bits 0-2 tell you about the version number. For example, I downloaded the file "Health Indicator Attributes" from the HRSA website. When I checked the first byte, I got '\x03', which converts to 0000 0011 in binary. The first three bits (on the far right, i.e. 011) are equivalent to 3, which according the DBF7 notes linked above indicates a DBF version 5 file.

I hope this helps. If you'd like, you can use this code as a template to create a DBF version 7 reader using the format link that I've provided. I only deal with older DBF versions, so I won't have any bandwidth to make updates to this project.

rnelsonchem avatar Dec 26 '17 19:12 rnelsonchem

same issues, still no updates on this?

erfannariman avatar May 02 '18 19:05 erfannariman

same issue, updates?

architsingh15 avatar Apr 09 '20 18:04 architsingh15

is there any alternative for this library? As I can see there is no support

rafdm avatar Jan 09 '21 12:01 rafdm

same issues, still no updates on this?

Enriquesec avatar Feb 23 '21 20:02 Enriquesec

Same issue!

File ~/.local/lib/python3.8/site-packages/simpledbf/simpledbf.py:557, in Dbf5.__init__(self, dbf, codec)
    554 self.columns = [f[0] for f in self.fields[1:]]
    556 terminator = self.f.read(1)
--> 557 assert terminator == b'\r'
    559 # Make a format string for extracting the data. In version 5 DBF, all
    560 # fields are some sort of structured string

ritaalamino avatar Aug 26 '22 18:08 ritaalamino

Same problem here... Please any fix for this?

roks531 avatar Nov 22 '22 09:11 roks531

Same problem here... any fix for this?

eolchina avatar Feb 07 '23 17:02 eolchina