473,805 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4171
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
2527
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 but the deployment (and long term upgrading) factor is a major itch which pyfreeze and py2exe just doesn't scratch properly. Thanks
1
1703
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. I need to know how to set or activate the compression values. here is the code I'm using: >import zipfile >zip = zipfile.ZipFile('<path/zipfilename.zip>', 'w')
2
1298
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 get stuck right in there? Mainly I'm trying to query lists of classes and their embedded versions and do some library dependency reporting. Performance speed is starting to be an issue, as there's 1500+ classes in this bucket and it's an...
0
312
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 ( +1) / 251 closed ( +0) / 518 total ( +1) New / Reopened Patches ______________________
9
2036
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 independent solution. Thx in advance, A.
0
1681
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 up if strerr: print >sys.stderr, strerr outlog.error(strerr)
2
17919
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 /usr/local/lib/python2.5/xml/sax/__init__.py ... Compiling /usr/local/lib/python2.5/xml/sax/_exceptions.py ... Compiling /usr/local/lib/python2.5/xml/sax/expatreader.py ...
10
38618
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 zip a flat number of files in one folder, but I am having heck of a time trying to zip the whole directory. I want to zip it all to a file called "help.zip", and I want it to retain the original file structure. Of my several tries, here is the...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.