469,927 Members | 1,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

cPickle EOF Error

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

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="r oopesh",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"

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

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 ?
File "cardManagement.py", line 28, in import_cards
print serial_no, id, cPickle.loads(data.tostring())

Feb 28 '07 #1
0 1667

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Drochom | last post: by
reply views Thread by Guenter Walser | last post: by
reply views Thread by Simon Dahlbacka | last post: by
1 post views Thread by A.B., Khalid | last post: by
5 posts views Thread by Marcus Lowland | last post: by
3 posts views Thread by Rune Strand | last post: by
4 posts views Thread by Martin Manns | last post: by
1 post views Thread by Carl J. Van Arsdall | last post: by
8 posts views Thread by Jeff Poole | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.