. Advertisement .
..3..
. Advertisement .
..4..
I get an error: “BadZipfile: File is not a zip file
” When I’m using Python 2.5 and i open zip files with Python’s zipfile module [ zipfile.ZipFile(“filex.zip”) ]
Here are the error details:
Traceback (most recent call last):
File "<module1>", line 5, in <module>
zipfile.ZipFile("c:/temp/test.zip")
File "C:\Python25\lib\zipfile.py", line 346, in init
self._GetContents()
File "C:\Python25\lib\zipfile.py", line 366, in _GetContents
self._RealGetContents()
File "C:\Python25\lib\zipfile.py", line 378, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file
END_BLOCK: 4096,
comment: '\x00',
data: '\xd6\xf6\x03\x00\x88,N8?<e\xf0q\xa8\x1cwK\x87\x0c(\x82a\xee\xc61N'1qN\x0b\x16K-\x9d\xd57w\x0f\xa31n\xf3dN\x9e\xb1s\xffu\xd1\.....', (truncated)
endrec: ['PK\x05\x06', 0, 0, 4, 4, 268, 199515, 0],
filesize: 199806L,
fpin: <open file 'c:/temp/test.zip', mode 'rb' at 0x045D4F98>,
start: 4073
How to fix the zipfile badzipfile file is not a zip file. Please give me some good ideas.
The cause: The cause of this error is that Python can be confused with files named file.
Solution: You can fix this error by renaming these files. If that doesn’t work, try the following code:
Files named file can cause confusion in python. Try naming it another name. If it STILL doesn’t work, you can try this code.
Gzip, renaming, tracing, and 7zip expressions are the most basic ways to overcome the problem (Zipfile.badzipfile: file is not a zip) in Python. In fact, these two options necessitate the installation of new modules.