I have two zip files, both of them open well with Windows Explorer and 7-zip.
However when i open them with Python's zipfile module [ zipfile.ZipFile("filex.zip") ], one of them gets opened but the other one gives error "BadZipfile: File is not a zip file
".
I've made sure that the latter one is a valid Zip File by opening it with 7-Zip and looking at its properties (says 7Zip.ZIP). When I open the file with a text editor, the first two characters are "PK", showing that it is indeed a zip file.
I'm using Python 2.5 and really don't have any clue how to go about for this. I've tried it both with Windows as well as Ubuntu and problem exists on both platforms.
Update: Traceback from Python 2.5.4 on Windows:
Traceback (most recent call last):
File "<module1>", line 5, in <module>
zipfile.ZipFile("c:/temp/test.zip")
File "C:Python25libzipfile.py", line 346, in init
self._GetContents()
File "C:Python25libzipfile.py", line 366, in _GetContents
self._RealGetContents()
File "C:Python25libzipfile.py", line 378, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file
Basically when the _EndRecData
function is called for getting data from End of Central Directory" record, the comment length checkout fails [ endrec[7] == len(comment) ].
The values of locals in the _EndRecData
function are as following:
END_BLOCK: 4096,
comment: 'x00',
data: 'xd6xf6x03x00x88,N8?<exf0qxa8x1cwKx87x0c(x82axeexc61N'1qNx0bx16K-x9dxd57wx0fxa31nxf3dNx9exb1sxffuxd1.....', (truncated)
endrec: ['PKx05x06', 0, 0, 4, 4, 268, 199515, 0],
filesize: 199806L,
fpin: <open file 'c:/temp/test.zip', mode 'rb' at 0x045D4F98>,
start: 4073
See Question&Answers more detail:
os