This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pickle error message unhelpful
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: jhylton, wabe0x90
Priority: normal Keywords:

Created on 2002-07-16 15:22 by wabe0x90, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg11601 - (view) Author: Dave Aitel (wabe0x90) Date: 2002-07-16 15:22
Version: Python 2.2 (#1, Feb 24 2002, 16:21:58) 
I was trying to pickle a class which had an open
socket, the exception  I got was:
File "/usr/lib/python2.2/pickle.py", line 969, in dump
    Pickler(file, bin).dump(object)
  File "/usr/lib/python2.2/pickle.py", line 115, in dump
    self.save(object)
  File "/usr/lib/python2.2/pickle.py", line 221, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 494, in
save_inst
    save(stuff)
  File "/usr/lib/python2.2/pickle.py", line 221, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 443, in
save_dict
    save(value)
  File "/usr/lib/python2.2/pickle.py", line 221, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 494, in
save_inst
    save(stuff)
  File "/usr/lib/python2.2/pickle.py", line 221, in save
    f(self, object)
  File "/usr/lib/python2.2/pickle.py", line 443, in
save_dict
    save(value)
  File "/usr/lib/python2.2/pickle.py", line 185, in save
    tup = reduce()
  File "/usr/lib/python2.2/copy_reg.py", line 57, in
_reduce
    state = base(self)
TypeError: an integer is required

Only by adding this to copy_reg.py was I able to figure
out what was really going on:
def _reduce(self):
    for base in self.__class__.__mro__:
        if hasattr(base, '__flags__') and not
base.__flags__ & _HEAPTYPE:
            break
    else:
        base = object # not really reachable
    if base is object:
        state = None
    else:
################I added the next line
        print "dave: type of self="+str(self)
        state = base(self)
    args = (self.__class__, base, state)


It would be REALLY nice if pickle returned some sort of
better error message so I didn't have to do that,
especially for beginers like myself. :>

msg11602 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-07-16 16:50
Logged In: YES 
user_id=31392

Can you provide some sample code that cause the obscure
error message?  When I tried to reproduce this problem, I
create an instance with a socket attribute.  When I pickled
it, I get a clear error message:

>>> import socket
>>> class Foo(object):
...     def __init__(self):
...             self.sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
... 
>>> f = Foo()
>>> pickle.dumps(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.3/pickle.py", line 1055, in dumps
    Pickler(file, bin).dump(object)
  File "/usr/local/lib/python2.3/pickle.py", line 165, in dump
    self.save(object)
  File "/usr/local/lib/python2.3/pickle.py", line 275, in save
    f(self, object)
  File "/usr/local/lib/python2.3/pickle.py", line 555, in
save_inst
    save(stuff)
  File "/usr/local/lib/python2.3/pickle.py", line 275, in save
    f(self, object)
  File "/usr/local/lib/python2.3/pickle.py", line 504, in
save_dict
    save(value)
  File "/usr/local/lib/python2.3/pickle.py", line 239, in save
    tup = reduce()
  File "/usr/local/lib/python2.3/copy_reg.py", line 57, in
_reduce
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle socket objects
msg11603 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-08-15 19:39
Logged In: YES 
user_id=31392

Closed for lack of response.
History
Date User Action Args
2022-04-10 16:05:30adminsetgithub: 36902
2002-07-16 15:22:27wabe0x90create