Take the 2-minute tour ×

I have a thread that constanlty waits for input via a socket. It receives things fine, but if I try to pickle.loads the string, then I receive an error. That would be an easy thing to catch, but this is the error it returns:

Exception in thread Listening to <socket._socketobject object at 0x232cd00> at ('', 48774):
Traceback (most recent call last):
  File "/home/[redacted]/Server.py", line 46, in Listen
    pickled = pickle.loads(data)
  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
  File "/usr/lib/python2.7/pickle.py", line 958, in load_binfloat
    self.append(unpack('>d', self.read(8))[0])
error: unpack requires a string argument of length 8

I have tried and successfully caught this with a simple try...except check with no specifications, but I have no idea how to catch this 'error', as pickle.struct.error only works for a few of the cases.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Right, turns out struct.error WAS the error that was not being caught...

share|improve this answer

Your Answer


