Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50219
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'error:': 0.07; 'referring': 0.07; 'result,': 0.07; 'string': 0.09; '-1)': 0.09; 'function:': 0.09; 'loaded,': 0.09; 'obj': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'django': 0.11; '(it': 0.16; 'a(object):': 0.16; 'effect.': 0.16; 'files)': 0.16; 'guys,': 0.16; 'hasattr(obj,': 0.16; 'means.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'set,': 0.16; 'sockets': 0.16; 'subject:class': 0.16; 'subject:object': 0.16; 'subject:type': 0.16; 'tuple,': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'module': 0.19; 'trying': 0.19; 'slightly': 0.19; '>>>': 0.22; 'import': 0.22; 'issue.': 0.22; 'load': 0.23; 'header:User-Agent:1': 0.23; 'error': 0.23; '(such': 0.24; 'helpful': 0.24; "haven't": 0.24; 'long,': 0.26; 'skip:" 30': 0.26; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; '"",': 0.31; 'fine,': 0.31; 'int,': 0.31; 'loads': 0.31; 'pickle': 0.31; 'produces': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'another': 0.32; '(most': 0.33; 'guess': 0.33; 'monday,': 0.33; 'maybe': 0.34; 'problem': 0.35; 'classes': 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'leads': 0.36; 'doing': 0.36; 'thanks': 0.36; 'hi,': 0.36; 'should': 0.36; 'being': 0.38; 'problems': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'that,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'temporarily': 0.60; 'most': 0.60; 'simple': 0.61; 'here:': 0.62; 'name': 0.63; 'kind': 0.63; 'happen': 0.63; 'july': 0.63; 'more': 0.64; 'complex,': 0.84; 'disappear': 0.84; 'float,': 0.84; 'imran': 0.84; 'object:': 0.84; 'otten': 0.84; 'peter,': 0.84; 'pickled': 0.84; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: UnpicklingError: NEWOBJ class argument isn't a type object |
| Date | Tue, 09 Jul 2013 09:24:41 +0200 |
| Organization | None |
| References | <18dd6d34-5afa-4324-bd2f-f5561413b156@googlegroups.com> <mailman.4367.1373269568.3114.python-list@python.org> <a34607d3-dd0b-4096-bb6a-2c320c7b4a32@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084acfa.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4434.1373354695.3114.python-list@python.org> (permalink) |
| Lines | 120 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1373354695 news.xs4all.nl 15999 [2001:888:2000:d::a6]:54224 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50219 |
Show key headers only | View raw
skunkwerk wrote:
> On Monday, July 8, 2013 12:45:55 AM UTC-7, Peter Otten wrote:
>> 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.
>
> Hey Peter,
> I tried unpickling even from another file with no other code in it, but
> came up with the same error - so I don't think it's a rebinding issue.
>
> But I got the error to disappear when I removed the "hasattr(obj,
> '__getstate__')" from this line of code in the persistent_id function: if
> not hasattr(obj, '__getstate__') and isinstance(obj,(basestring, bool,
> int, long, float, complex, tuple, list, set, dict)):
> return ["filtered:%s" % type(obj)]
>
> When I do that, I get a few more FilteredObjects in the result, for things
> like: <class 'django.core.handlers.wsgi.WSGIRequest'>
> <class 'MySQLdb.connections.Connection'>
>
> I figured these classes must have __getstate__ methods which leads to them
> being pickled without a persistent_id (it turns out they actually have
> __repr__ methods).
>
> So these classes get pickled fine, but run into problems when trying to
> unpickle them. I understand why ImportErrors would happen if the
> necessary modules haven't been loaded, but this NEWOBJ error is still kind
> of mystifying. I guess I just won't pickle any classes for now, if
> unpickling them is going to be dicey.
>
> thanks for the help guys,
> imran
Maybe you can find the problem by temporarily switching from cPickle to the
pickle module which produces a slightly more helpful traceback:
>>> import cPickle, pickle
>>> class A(object): pass
...
>>> p = cPickle.dumps(A(), -1)
>>> 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
>>> pickle.loads(p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/pickle.py", line 1382, in loads
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1083, in load_newobj
obj = cls.__new__(cls, *args)
TypeError: int.__new__(X): X is not a type object (int)
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
UnpicklingError: NEWOBJ class argument isn't a type object skunkwerk <skunkwerk@gmail.com> - 2013-07-07 22:27 -0700
Re: UnpicklingError: NEWOBJ class argument isn't a type object Chris Angelico <rosuav@gmail.com> - 2013-07-08 15:57 +1000
Re: UnpicklingError: NEWOBJ class argument isn't a type object dieter <dieter@handshake.de> - 2013-07-08 08:53 +0200
Re: UnpicklingError: NEWOBJ class argument isn't a type object Peter Otten <__peter__@web.de> - 2013-07-08 09:45 +0200
Re: UnpicklingError: NEWOBJ class argument isn't a type object skunkwerk <skunkwerk@gmail.com> - 2013-07-08 16:38 -0700
Re: UnpicklingError: NEWOBJ class argument isn't a type object Peter Otten <__peter__@web.de> - 2013-07-09 09:24 +0200
csiph-web