UnpicklingError: NEWOBJ class argument isn't a type object

Peter Otten __peter__ at web.de
Mon Jul 8 09:45:55 CEST 2013


skunkwerk wrote:

> Hi,
>   I'm using a custom pickler that replaces any un-pickleable objects (such
>   as sockets or files) with a string representation of them, based on the
>   code from Shane Hathaway here:
> http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with-
some-unpicklable-items
> 
> It works most of the time, but when I try to unpickle a Django
> HttpResponse, I get the following error: UnpicklingError: NEWOBJ class
> argument isn't a type object
> 
> I have no clue what the error actually means.  If it pickles okay, why
> should it not be able to unpickle?  Any ideas?

A simple way to provoke the error is to rebind the name referring to the 
class of the pickled object:

>>> import cPickle
>>> class A(object): pass
... 
>>> p = cPickle.dumps(A(), -1)
>>> cPickle.loads(p)
<__main__.A object at 0x7fce7bb58c50>
>>> A = 42
>>> cPickle.loads(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cPickle.UnpicklingError: NEWOBJ class argument isn't a type object

You may be doing something to that effect.




More information about the Python-list mailing list