Problem pickling exceptions in Python 2.5/2.6

Irmen de Jong irmen.NOSPAM at
Sun Jun 8 12:11:16 CEST 2008

I'm having troubles pickling classes that extend Exception.

Given the following source:

class Foo(object):
     def __init__(self, m):

class Bar(Exception):
     def __init__(self, m):

import pickle
pickle.loads(s)  # normal object works
pickle.loads(s)  # exception object fails

When running this in Python 2.5 or Python 2.6a, it crashes on the last line, with:

Traceback (most recent call last):
   File "", line 14, in <module>
     pickle.loads(s)  # exception object fails
   File "C:\Python25\lib\", line 1374, in loads
     return Unpickler(file).load()
   File "C:\Python25\lib\", line 858, in load
   File "C:\Python25\lib\", line 1133, in load_reduc
     value = func(*args)
TypeError: __init__() takes exactly 2 arguments (1 given)

This used to work fine in Python 2.3 and 2.4...
What has been changed in 2.5? Is there a way to get rid of the error?
(I tried some stuff with __getinitargs__ and __getnewargs__ but couldn't get it to work).


More information about the Python-list mailing list