N
N
niko832012-11-22 18:21:20
Django
niko83, 2012-11-22 18:21:20

Python. What is the correct way to store a pickle object in Mysql?

I'm trying to store a packed pickle object in MySql:

message = pickle.dumps(u'\xe7')<br>
MyModel(message=message).save()<br>

I get Warning: Incorrect string value: '\xE7\x0Ap0\x0A.' for column 'message'
We managed to find solutions: and
message = pickle.dumps(u'\xe7').decode('base64')
from django.utils.encoding import smart_str<br>
message = pickle.dumps(smart_str(u'\xe7'))

But it seems to me that there is a better solution to save objects containing strings like u'\xe7'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin, 2012-11-22
@Norraxx

I have a feeling the problem here is a bit different. docs.python.org/2/howto/unicode.html

N
nochkin, 2012-11-23
@nochkin

As an alternative, make the field in the database binary (for example, BLOB).

M
Maxim Vasiliev, 2012-11-23
@qmax

unearth django.contrib.sessions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question