467,188 Members | 1,417 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

Bad magic no. in python zipfile

I've been experimenting with the python zipfile module, and have run
into a snag.

I'm able to create a new zipfile with the module's ZipFile class and
add files to it. After closing the file, I'm able to view the contents
of it with WinZip. I can also confirm that it is a python zip file by
using the is_zipfile() method. All good so far. However, under some
circumstances, I am unable to later read the file and extract its
contents. As soon as a I attempt to instantiate a new ZipFile
instance, I receive an error regarding Bad Magic number. In the past,
I've seen that when trying to use a .pyc module, created with one
Python version, using another Python version. But in this case, I
created the zip file under Python 2.4.2 and tried to open it under
Python 2.4.2 as well. Any ideas on what to do? (apart from giving up
on Python and using winzip?)

On a separate topic, zipfile wasn't available under Python 1.5.2. I
need to create zip files using that old version, since it's the only
one installed on a remote server. Any suggestions on what to do?

thanks
S

Oct 13 '05 #1
  • viewed: 3351
Share:
2 Replies
st***************@gmail.com wrote:
\> I'm able to create a new zipfile with the module's ZipFile class and
add files to it. After closing the file, I'm able to view the contents
of it with WinZip. I can also confirm that it is a python zip file by
using the is_zipfile() method. All good so far. However, under some
circumstances, I am unable to later read the file and extract its
contents. As soon as a I attempt to instantiate a new ZipFile
instance, I receive an error regarding Bad Magic number. In the past,
I've seen that when trying to use a .pyc module, created with one
Python version, using another Python version. But in this case, I
created the zip file under Python 2.4.2 and tried to open it under
Python 2.4.2 as well. Any ideas on what to do?


Maybe try posting the full traceback so we can see the "Bad Magic
Number" error you are getting...

-Peter
Oct 13 '05 #2
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

Oct 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by huy | last post: by
1 post views Thread by deejaay@swbell.net | last post: by
2 posts views Thread by Andy Dingley | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
2 posts views Thread by fartknuckle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.