biznez
biznez

Reputation: 4021

BDB Python Interface Error when Reading BDB

bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- /dbs/supermodels.db: unexpected file type or format')

Is this error a result of incompatible BDB versions (1.85 or 3+)? If so, how do I check the versions, trouble-shoot and solve this error?

Upvotes: 1

Views: 3094

Answers (1)

mhawke
mhawke

Reputation: 87064

Yes, this certainly could be due to older versions of the db file, but it would help if you posted the code that generated this exception and the full traceback.

In the absence of this, are you sure that the database file that you're opening is of the correct type? For example, attempting to open a btree file as if it is a hash raises the exception that you are seeing:

>>> import bsddb
>>> bt = bsddb.btopen('bt')
>>> bt.close()
>>> bsddb.hashopen('bt')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/bsddb/__init__.py", line 298, in hashopen
    d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./bt: unexpected file type or format')

In *nix you can usually determine the type of db by using the file command, e.g.

$ file /etc/aliases.db cert8.db 
/etc/aliases.db: Berkeley DB (Hash, version 8, native byte-order)
cert8.db:        Berkeley DB 1.85 (Hash, version 2, native byte-order)

Opening a 1.85 version file fails with the same exception:

>>> db = bsddb.hashopen('/etc/aliases.db')    # works, but...
>>> db = bsddb.hashopen('cert8.db')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/bsddb/__init__.py", line 298, in hashopen
    d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./cert8.db: unexpected file type or format')

If you need to migrate the database files, you should look at the db_dump, db_dump185 and db_load utilities that come with the bdb distribuition.

Upvotes: 1

Related Questions