[Tutor] perplexing error with shelve REVISED

Kent Johnson kent37 at tds.net
Wed Oct 31 23:51:00 CET 2007


Orest Kozyar wrote:
>> Please post the entire traceback (omitting duplicate lines). 
> 
> Sorry, I should have included the traceback.  I've revised the sample script
> so that it generates the traceback when run.  The sample script is at the
> very bottom of this email.

I've poked at this a little. The problem is in the pickling of the 
minidom object. It fails for me using
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin

If you use pickle instead of cPickle the stack trace at least shows the 
recursive calls.

Here is a slightly shorter program that demonstrates the problem a 
little better:

import urllib
from pickle import Pickler
from cStringIO import StringIO
from xml.dom import minidom

baseurl = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?'

params = {
         'db':       'pubmed',
         'retmode':  'xml',
         'rettype':  'medline',
         }

badkey = '16842422'

params['id'] = badkey
url = baseurl + urllib.urlencode(params)
doc = minidom.parseString(urllib.urlopen(url).read())
print 'Successfully retrieved and parsed XML document with ID %s' % badkey

f = StringIO()
p = Pickler(f, 0)
p.dump(doc)

#Will fail on the above line
print 'Successfully shelved XML document with ID %s' % badkey


Here is the top of the stack trace:
   File "BadShelve.py", line 35, in <module>
     p.dump(doc)
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 224, in dump
     self.save(obj)
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 286, in save
     f(self, obj) # Call unbound method with explicit self
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 725, in save_inst
     save(stuff)
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 286, in save
     f(self, obj) # Call unbound method with explicit self
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 649, in save_dict
     self._batch_setitems(obj.iteritems())
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 663, in _batch_setitems
     save(v)
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 286, in save
     f(self, obj) # Call unbound method with explicit self
   File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", 
line 725, in save_inst
     save(stuff)


You might want to take this to comp.lang.python or perhaps xml-sig.

Kent


More information about the Tutor mailing list