[docs] [issue23174] shelve.open fails with error "anydbm.error: db type could not be determined"

R. David Murray report at bugs.python.org
Tue Jan 6 09:22:58 CET 2015


R. David Murray added the comment:

The problem is that this is not the only situation in which that error can be generated.  If someone passed in an "old" (and possibly non-empty) file with no extension, the same code path would get executed.

The shelve/anydbm API is database agnostic, so there is no way to know a-priori what the valid extensions are.  The whichdbm module (which anydbm uses) could provide this information in theory, but it doesn't currently, and if it did that would be a new API.

Your problem is that the shelve API is designed so that you either pass it the base name of an existing database, *or* you pass it the base name of a *non* existent database, which it then creates all the right files for (there may be more than one file).  The fact that you are passing it a new existing file is the problem, and I'm not sure the error message can be effectively improved to handle that particular mistaken use of the API without breaking the message for the places it is more meaningful.

The best I can think of is to add the filename to the error message and list all the extensions and (if there are any) the 'magic' type guesses that whichdbm tried, but as I said that would be a new feature and thus could only go into 3.5.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23174>
_______________________________________


More information about the docs mailing list