Python pickle index out of range - python

I'm getting the following error when i try to run my py file on a windows machine, everything works fine from the Mac, but i cant get the two machines to talk to one another. do i have to 'dumps' in ascii; if so how do i do that? any suggestions? THANKS!!
Traceback (most recent call last):
File "C:\Users\Keith\Desktop\rcserver\tcpserver_simpleReceive.py", line 23, in <module>
new_data = pickle.loads(data)
File "C:\Python27\lib\pickle.py", line 1382, in loads
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1165, in load_put
self.memo[self.readline()[:-1]] = self.stack[-1]
IndexError: list index out of range
The dumps:
if e.type == pygame.JOYAXISMOTION:
client_socket.sendall (pickle.dumps(e.dict,0))
this is the loads:
data = client_socket.recv(1024)
new_data = pickle.loads(data)

Related

ValueError: reading array data - while loading pickle file using joblib

I am trying to load a pickle file which i created using joblib.dump()
The dumping code looks like:
from sklearn.externals import joblib
with open('sample.pickle','wb') as f:
joblib.dump([x,y],f)
This works fine and my sample.pickle is saved successfully. But when i try to load this file:
with open('sample.pickle', 'rb') as f:
x, y = joblib.load(f)
I get the following error:
ValueError: EOF: reading array data, expected 1200 bytes got 0
The full error log looks like this:
Traceback (most recent call last):
File "model.py", line 16, in <module>
vec_x, vec_y = joblib.load(f)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 568, in load
obj = _unpickle(fobj)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 508, in _unpickle
obj = unpickler.load()
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\pickle.py", line 1050, in load
dispatch[key[0]](self)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 341, in load_build
self.stack.append(array_wrapper.read(self))
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 184, in read
array = self.read_array(unpickler)
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 135, in read_array
read_size, "array data")
File "C:\Users\acer_pc\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\numpy_pickle_utils.py", line 646, in _read_bytes
raise ValueError(msg % (error_template, size, len(data)))
ValueError: EOF: reading array data, expected 1200 bytes got 0
By the way, i am very new to dumping and pickling.
Any help will be appreciated. Thanks in advance.

Python - Pickle insecure string error when loading string

Error:
Traceback (most recent call last): File "C:\Users\user\Documents\Elly\client.py", line 12, in <module>
a = pickle.loads(b) File "C:\Python27\lib\pickle.py", line 1382, in loads
return Unpickler(file).load() File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self) File "C:\Python27\lib\pickle.py", line 966, in load_string
raise ValueError, "insecure string pickle" ValueError: insecure string pickle
Client:
cl = socket.socket()
cl.connect(("127.0.0.1",8869))
act = data.listFiles(1, "")
cl.send(pickle.dumps(act))
b = cl.recv(4196*8)
a = pickle.loads(b)
act = a.getResult()
print act
Server:
rawrecv = self.client_socket.recv(4196*2)
act = pickle.loads(rawrecv)
act.work()
self.client_socket.send(pickle.dumps(act.getResult()))
My whole project depends on serializing via sockets, help?
Found my problem, I sent it over sockets and the maxsize is 8k bytes so it just cut it.

Type error on unpickle

I have a dictionary that's pickled into a file "offsets.pickle". When I try to unpickle it with
import pickle
a = open('offsets.pickle')
b = pickle.load(a)
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/global/python-2.7.3-intel/lib/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/global/python-2.7.3-intel/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/global/python-2.7.3-intel/lib/python2.7/pickle.py", line 1198, in load_setitem
dict[key] = value
TypeError: 'str' object does not support item assignment
My code runs nightly and was running fine for a while, when suddenly this started to happen. Is it possible for me to recover what is stored in the file?

Error on deserialization with pickle python

I am new to python. I have a file data.pkl. What I would like to do is get the data from the file. I looked at http://docs.python.org/library/pickle.html, 11.1.7 example and tried exactly that.
My code looks like this:
import pprint, pickle
pkl_file = open('data.pkl', 'rb')
data1 = pickle.load(pkl_file)
pprint.pprint(data1)
pkl_file.close()
But it is giving me error:
Traceback (most recent call last):
File "/home/sadiksha/workspace/python/test.py", line 5, in <module>
data1 = pickle.load(pkl_file)
File "/usr/lib/python2.7/pickle.py", line 1378, in load
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 966, in load_string
raise ValueError, "insecure string pickle"
Can anyone please tell me what am I doing wrong here?
It seems that your pickle file was either not written correctly (specifying 'wb') or the file was somehow corrupted. Try creating your own pickle file and reading that back in. That should do the trick.
As for the pickle file specified, it is definitely corrupted.

Pickle: Reading a dictionary, EOFError

I recently found out about pickle, which is amazing. But it errors on me when used for my actual script, testing it with a one item dictionary it worked fine. My real script is thousands of lines of code storing various objects within maya into it. I do not know if it has anything to do with the size, I have read around a lot of threads here but none are specific to my error.
I have tried writing with all priorities. No luck.
This is my output code:
output = open('locatorsDump.pkl', 'wb')
pickle.dump(l.locators, output, -1)
output.close()
This is my read code:
jntdump = open('locatorsDump.pkl', 'rb')
test = pickle.load(jntdump)
jntdump.close()
This is the error:
# Error: Error in maya.utils._guiExceptHook:
# File "C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\pymel-1.0.0-py2.6.egg\maya\utils.py", line 277, in formatGuiException
# exceptionMsg = excLines[-1].split(':',1)[1].strip()
# IndexError: list index out of range
#
# Original exception was:
# Traceback (most recent call last):
# File "<maya console>", line 3, in <module>
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 1370, in load
# return Unpickler(file).load()
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 858, in load
# dispatch[key](self)
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 880, in load_eof
# raise EOFError
# EOFError #
Try using pickle.dumps() and pickle.loads() as a test.
If you don't recieve the same error, you know it is related to the file write.

Categories

Resources