I am pickling Python Objects in Django and saving it in MySQL db. So far i have followed these simple rules:
cPickle.dumps(object)
#to convert
If you are trying to store the output of cPickle.dumps
in a VARCHAR
column, then your issue is that you are trying to store a byte-string in a character column. The fix in that case is to encode your object as unicode(base64.encode(cPickle.dumps(myobject)))
and then store it.
Alternatively:
object2varchar = lambda obj: unicode(base64.encode(cPickle.dumps(obj)))
store(object2varchar([1, 'foo']))