Search code examples
pythonpickle

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


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)

Solution

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