473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 4133
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 would love to start my new project using Python...
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 compression. 120M file stays 120M within the zip package....
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 JARs? Or do I just treat them as plain zipfiles and...
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 closed ( +7) / 7473 total (+15) RFE : 267 open...
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 python on. I obviously look for platform...
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)) strerr = ferr.read() # This makes the program hanging...
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 /usr/local/lib/python2.5/xml/sax ... Compiling...
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 each file in my directory, and I can use zipfile to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.