472,337 Members | 1,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

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
2 4041
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: huy | last post by:
Hi, Just wondering if there were any plans (or existing projects) similar to Java webstart for Python. I think this would be a boon for python. I...
1
by: deejaay | last post by:
Hello, I following an example on how to zip files from the www.devshed.com site. I can create a zip package, however I am not getting any...
2
by: Andy Dingley | last post by:
I run build processes for a Java shop using Python (and some Ant). Would anyone care to suggest favoured tools for manipulating the innards of...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 408 open ( -9) / 3585 closed (+20) / 3993 total (+11) Bugs : 968 open ( +8) / 6505...
9
by: alf | last post by:
Hi, I have a small app which consist of a few .py files. Is there any way to distribute it in jar like fashion as a single file I can just run...
0
by: Rocky Zhou | last post by:
python unzip At first, I tried to use 'os.popen3("unzip ...") like this: fin, fout, ferr = os.popen3("unzip -o -d %s %s" % (dest, zipfile))...
2
by: fartknuckle | last post by:
When I try to build and install python from source It configures and makes fine but upon 'make install' I always get to this point: Listing...
10
by: Bertsche | last post by:
I'm relatively new to python, and am trying to zip a directory containing several levels of files and folders. I can use the walk function to name...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.