Storing Pickled Data in Mysql
I am trying to use pickle to store an object in mysql, but no matter what
I do, I can't seem to unpickle the data.
My mysql database
http://i.imgur.com/xCyZtIO.png
My mysql connect function
conn = MySQLdb.connect (host = "localhost", user = "user", passwd =
"password", db = 'database', use_unicode=True)
Storing the data
cursor.execute('UPDATE matchmaking set `elo` = %s WHERE `token` = %s',
(pickle.dumps(Rating()) , y[0] ))
Loading the data
cursor.execute('SELECT * FROM matchmaking where `gameid` = %s LIMIT 200',
(row[0]))
player1 = pickle.loads(player[x][2])
KeyError: '"'
print player[x]
(u'35dc00eeb1fa2a49efcae7d2a8233cef', 1L,
'"ccopy_reg\n_reconstructor\np0\n(ctrueskill\nRating\np1\nc_builtin_\nobject\np2\nNtp3\nRp4\n(dp5\nS\'tau\'\np6\nF0.35999999999999993\nsS\'pi\'\np7\nF0.014399999999999998\nsb."',
2L)
No comments:
Post a Comment