我有一个线程不断等待通过套接字输入。它接收的东西很好,但是如果我尝试pickle.loads
使用字符串,那么我会收到一个错误。这将是一件容易的事情,但这是它返回的错误:
Exception in thread Listening to <socket._socketobject object at 0x232cd00> at ('127.0.0.1', 48774):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
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
dispatch[key](self)
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
我已经尝试并通过没有规范的简单try...except
检查成功地捕捉到了这一点,但我不知道如何捕捉这个“错误”,因为pickle.struct.error
它只适用于少数情况。