I am trying to save a file as a BLOB in a MySQL database. The DB is very simple right now, a table with One column "File" as type longblob.
The code is as follows:
file = open("file.txt","r")
data = file.readlines()
dp = pickle.dumps(data,1)
sql = "insert into Files values (%s)"
cursor.execute(sql,(MySQLdb.escape_string(dp),))
This seems to upload fine, however when retrieving the data, I get an EOFError when trying to unpickle. If I try the process without pickling at all, the string is not unescaped and the escape characters stay in the string when written back to the file (unless there is a python step I am missing there to unescape/re-escape).
sql = "select File from Files"
cursor.execute(sql)
ret = cursor.fetchone()
pickle.loads(ret[0])
EOFError exception