3

I downloaded some zip files but I cant use zipfile module to unzip them.

import zipfile
z = zipfile.ZipFile("00951999AP.wtl","r")
BadZipfile: File is not a zip file

File says it is a multifile-zip, but I know it isn't because I can unzip it on b1freearchiver

file 00951999AP.wtl
00951999AP.wtl: Zip multi-volume archive data, at least PKZIP v2.50 to extract

What should I do?

In [11]: zipfile.ZipFile("00951999AP.wtl")
---------------------------------------------------------------------------
BadZipfile                                Traceback (most recent call last)
<ipython-input-11-05921d85d623> in <module>()
----> 1 zipfile.ZipFile("00951999AP.wtl")

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.pyc in __init__(self, file, mode, compression, allowZip64)
    710 
    711         if key == 'r':
--> 712             self._GetContents()
    713         elif key == 'w':
    714             # set the modified flag so central directory gets written

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.pyc in _GetContents(self)
    744         is bad."""
    745         try:
--> 746             self._RealGetContents()
    747         except BadZipfile:
    748             if not self._filePassed:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.pyc in _RealGetContents(self)
    759             raise BadZipfile("File is not a zip file")
    760         if not endrec:
--> 761             raise BadZipfile, "File is not a zip file"
    762         if self.debug > 1:
    763             print endrec

BadZipfile: File is not a zip file
Dharman
  • 30,962
  • 25
  • 85
  • 135
Coelhao
  • 31
  • 3
  • 1
    You're in the right directory, right? – user2357112 Aug 04 '14 at 07:06
  • What kind of file does B1 say it is? – user2357112 Aug 04 '14 at 07:12
  • 1
    Can you show us the *full* traceback? E.g. at what line exactly is the `BadZipFile` exception thrown? – Martijn Pieters Aug 04 '14 at 07:12
  • Python certainly does not agree that is a zipfile object; it tries reads the zipfile record from the end of the file, and that fails, either because the data found there doesn't fit the Zip specification or the file isn't big enough to contain that info. I suspect that the `file` command is far less rigorous in its test and gave you a false positive. Can a command-line tool like `unzip` extract the file? – Martijn Pieters Aug 04 '14 at 07:20
  • 3
    I noticed only now that `file` tells you it is a *multi-volume* ZIP file. Python does not support multi-volume ZIPs, although it should have given you a better error message. This supports the hypothesis that `file` got it wrong. – Martijn Pieters Aug 04 '14 at 07:23
  • is there any alternative lib for zip files? – Coelhao Aug 04 '14 at 07:32

0 Answers0