Skip to content
Advertisement

Bad magic number error with ZipFile module in Python

I am using Python 2.7 on Windows 7 (64 bit). When I try to unzip a zip file with ZipFile module I get the following error:-

JavaScript

WinRAR could extract the file I am trying to extract just fine. Here is the code I used to extract files from myzip.zip

JavaScript

This code is working fine for many other zip files I created using WinRAR but myzip.zip

I tried commenting the following lines in Python27Libzipfile.py:-

JavaScript

But this didn’t really help. Running my code with this in effect, I get some dump on my shell.

Advertisement

Answer

Correct ZIP files always have “x50x4Bx03x04” in the beginning. You can test whether file is really ZIP file with this code:

JavaScript

It will print header of file so you can check.

UPDATE Strange, testzip() and all other functions work good. Had you tried such code?

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement