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

Question:

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)
Asked By: liv2hak

||

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().

Answered By: 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

Answered By: Nnamani Ugochukwu
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.