Bad magic no. in python zipfile

stewart.midwinter at gmail.com stewart.midwinter at gmail.com
Thu Oct 13 22:10:20 EDT 2005


okay, I've figured out the problem - the zip file was being mangled by
a file transfer.  I was fetching a remote python-generated zip file in
8k chunks, and then writing those chunks to a file.  At first I was
using an array to store the data in, and had the 'bad magic number'
problem.  This may have been due to writing the chunks out to a local
file as strings, which would definitely have corrupted the file; I also
noticed that the local copy was several kb larger, probably due to the
line endings being added.  When I took care to write the file as a
binary file, all was well. case closed.

BTW, regarding using zipfile under Python 1.5.2... I found zipfile.py
in Python 1.6, but it wouldn't run.  You need to build Python 1.5 with
the binascii.c and zlibmodule.c from Python 1.6, since a CRC32 method
has been added to those modules.  This was more trouble than it was
worth, in the end. 

S




More information about the Python-list mailing list