0
我有一個線程,constanlty通過套接字等待輸入。它收到的東西很好,但如果我嘗試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
僅適用於少數情況。