Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`_pickle.UnpicklingError: the STRING opcode argument must be quoted`

Tags:

python

pickle

I have a text file that I am trying to picke using python pickle.

tx b'88877343430010000000000'
tx b'59343410000000000'
rx b'344454320000000004'

I am using the following python code to serialize the file.I am getting the following error. _pickle.UnpicklingError: the STRING opcode argument must be quoted. I can't find anything wrong with the pickle file.

import six.moves.cPickle
file = open('test.txt', 'rb')        
loaded = six.moves.cPickles.load(file)
like image 296
liv2hak Avatar asked Sep 04 '25 01:09

liv2hak


2 Answers

When you use cPickle.load() you are trying to unpickle (deserialize) a previously pickled file into a Python object.

To pickle (serialize) an object to a file you should use cPickle.dump().

like image 52
Galax Avatar answered Sep 07 '25 00:09

Galax


This issue occurs if the file you are trying to load wasn't generated by the same version of the pickle library as you are using, that may not be possible. The solution to this is to open the file and save it again without editing anything and then go back and rerun your program.

Create an object similar to the one that you want to load and see how

like image 33
Nnamani Ugochukwu Avatar answered Sep 06 '25 23:09

Nnamani Ugochukwu