The shelve db type cannot be determined, whichdb does not recognize gdb

Why does a shelf cause an error if I try to open a file created only by the shelf?

import shelve info_file_name = "/Users/bacon/myproject/temp/test.info" info_file = shelve.open(info_file_name) info_file['ok'] = 'wass' info_file.close() info_file = shelve.open(info_file_name) # raise exception db type could not be determined.. info_file.close() 

I am running python 2.5 in case it is relevant

The exact mistake is to increase:

db type could not be determined , called by anydbm.py open method.

I know this using gdbm. I checked whatdb.py file and tried to identify gdbm files with this

  # Read the start of the file -- the magic number s16 = f.read(16) s = s16[0:4] # Convert to 4-byte int in native byte order -- return "" if impossible (magic,) = struct.unpack("=l", s) # Check for GNU dbm if magic == 0x13579ace: return "gdbm" 

But the number "magic" in my file is 324508367 ( 0x13579acf ) (only the last change in the number!)

I tried to open the file with a different language (ruby) and I was able to open it without any problems, so this seems to be an error in whodb.py trying to determine the correct dbm

+1
source share
1 answer

As explained in this question, this error was caused by the error that db, which cannot identify some latest gdb files, has more information in this error report: https://bugs.python.org/issue13007

The best solution is to get db to define a method that loads the shelf with gdbm instead of trying to guess dbm.

 def gdbm_shelve(filename, flag="c"): mod = __import__("gdbm") return shelve.Shelf(mod.open(filename, flag)) 

And then use it instead of shelve.open :

 info_file = gdbm_shelve(info_file_name) 
+1
source

Source: https://habr.com/ru/post/945643/


All Articles