Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndreMikulec opened this issue Sep 4, 2016 · 12 comments
Open

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

AndreMikulec opened this issue Sep 4, 2016 · 12 comments

Comments

@AndreMikulec
Copy link

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

@jdovi
Copy link

jdovi commented Oct 21, 2016

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

@daren-thomas
Copy link

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

@melanatech
Copy link

Any update on this?

@vanboom
Copy link

vanboom commented Dec 26, 2017

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

@rnelsonchem
Copy link
Owner

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.

@erfannariman
Copy link

same issues, still no updates on this?

@architsingh15
Copy link

same issue, updates?

@rafdm
Copy link

rafdm commented Jan 9, 2021

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

@Enriquesec
Copy link

same issues, still no updates on this?

@ritaalamino
Copy link

ritaalamino commented Aug 26, 2022

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

@roks531
Copy link

roks531 commented Nov 22, 2022

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

@eolchina
Copy link

eolchina commented Feb 7, 2023

Same problem here... any fix for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests