cPickle EOF Error



I am trying to write xml files which are inside a zip file into the
database.

In the zipfile module the function read returns bytes. What I did was
to make a blob out of the returned bytes and write it to the
database(for this I used cPickle). I also used _mysql's escape_string
which escapes some characters (without this the file content was not
getting written). But once we try to unpickle the content, an EOF
error is getting thrown. When I tried putting the content(xml in
database) to a file without unpickling then the xml file with escape
characters gets printed.

My code is as follows :

def import_cards():
try :
conn =
MySQLdb.connect(host="localhost",port=3306,user="roopesh",passwd="pass",db="mydbs")

cursor = conn.cursor()

cursor.execute("CREATE TABLE card (serial_no int(10),
id varchar(50), data blob, used char(1), ip varchar(20),
date_downloaded datetime)")

z = zipfile.ZipFile('/home/roopesh/public_html/
cards.zip', 'r')

sql = "INSERT INTO card (serial_no, id, data, used)
values (%s, %s, %s, %s)"


for filename in z.namelist() :
bytes = z.read(filename)
data = cPickle.dumps(bytes, 2)
#print data
cursor.execute(sql, (1, filename ,
_mysql.escape_string(data), 'n'))

sql = "SELECT serial_no, id, data, used FROM card"

cursor.execute(sql)
for serial_no, id, data, used in cursor.fetchall() :
print serial_no, id,
cPickle.loads(data.tostring())
# f = open(id ,'wb')
# f.write(data.tostring())
finally :
cursor.execute("DROP TABLE card")
conn.close()

return True

The output is :
--------------------
roopesh@dg:~/public_html$ python cardManagement.py
1 cards/passcard1.xml
Traceback (most recent call last):
File "cardManagement.py", line 136, in ?
import_cards()
File "cardManagement.py", line 28, in import_cards
print serial_no, id, cPickle.loads(data.tostring())
EOFError

.



Relevant Pages

  • RE: database with pictures for baseball card collection
    ... filename of your card. ... database size very easily. ... store the filename of the image. ... Current event to set the Picture property of an image control to the filename ...
    (microsoft.public.access.tablesdbdesign)
  • RE: database with pictures for baseball card collection
    ... change the Picture property of the image control. ... filename of your card. ... database size very easily. ... store the filename of the image. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: SQL CE 3.5 and Data Loss on SD Card
    ... sure the SD card is ready before we attempt data access. ... You might consider changing the flush interval on the connection string to ... with a database on SD card I would be greatful. ...
    (microsoft.public.sqlserver.ce)
  • Re: SQL CE 3.5 and Data Loss on SD Card
    ... devices we have experienced only one corrupted SDF database. ... I attribute our success to opening a connection just before every DB access ... some code that checks to make sure the SD card is ready before attempting ... The message was checked by ESET Smart Security. ...
    (microsoft.public.sqlserver.ce)
  • Re: SQL CE 3.5 and Data Loss on SD Card
    ... with a database on SD card I would be greatful. ... devices we have experienced only one corrupted SDF database. ... I attribute our success to opening a connection just before every DB access ...
    (microsoft.public.sqlserver.ce)