I work with a shelf in python 2.7.6 to cache calculations, and I ran into the problem described HERE for storing the files I created and implemented the proposed solution in a function that combines the other file into the target file:
... # target and other are strings # Loads the gdbm module, as suggested mod = __import__("gdbm") # Open target for modifications tar = shelve.Shelf(mod.open(target, 'c', 0666)) # THROWS EXCEPTION # Open other for reading oth = shelve.Shelf(mod.open(other, 'r')) ...
Two files belong to me, are written to the local file system and have posix permissions set to 0666 or, equivalently, -rw-rw-rw- in my Linux Mint box, so obvious checks were made:
$ ls -l -rw-rw-rw- 1 myusr mygrp 11694080 Sep 17 21:24 cache -rw-rw-rw- 1 myusr mygrp 12189696 Sep 17 21:23 cache.0
Here cache is target , and cache.0 is the other file. The current working directory belongs to me and has permissions 0775 , and I can create files with touch , cp , etc. At my discretion, no problem, and I even set my umask to 0000 , so new files are created with permissions 0666 or, equivalently, -rw-rw-rw- .
I even compared the actual file permissions with the permissions in the gdbm.open () call according to its documentation ; however, to no avail.
Refresh . By running python code with sudo , that is, with superuser privileges, the error occurs on the same line; however with another message: gdbm error: Bad magic number ! This is very strange, since the point of use of the (apparently) lower level module ( gdbm as opposed to shelve ) was exactly bypassing the detection of the database type.
Update # 2 : running python whichdb.py in files returns dbhash ; however, changing the module to dbhash in the boot code still gives the following errors:
bsddb.db.DBAccessError: (13, 'Permission denied')
when working as a user but
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- BDB0210 ././merge-cache.py: metadata page checksum error')
when starting with sudo; merge-cache.py is my code name.
This new bug is discussed here in connection with the python version, but (i) my python version is different from the one in this post, and (ii) files are created and later read with the same python version.
This answer indicates that the shelve gets "wasted" with large sets, but the problem I'm reporting is also happening with smaller databases.
Question: How to open these files with shelves using python-2.7.6? (updating python is not an option).