BadZipfile "file is not a zip file"

webcomm ryandw at
Fri Jan 9 01:47:39 CET 2009

The error...

>>> file = zipfile.ZipFile('', "r")
Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    file = zipfile.ZipFile('', "r")
  File "C:\Python25\lib\", line 346, in __init__
  File "C:\Python25\lib\", line 366, in _GetContents
  File "C:\Python25\lib\", line 378, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

When I look at in Windows, it appears to be a valid zip
file.  I am able to uncompress it in Windows XP, and can also
uncompress it with 7-Zip.  It looks like zipfile is not able to read a
"table of contents" in the zip file.  That's not a concept I'm
familiar with. is created in this script...

    decoded = base64.b64decode(datum)
    f = open('', 'wb')
    file = zipfile.ZipFile('', "r")

datum is a base64 encoded zip file.  Again, I am able to open
as if it's a valid zip file.  Maybe there is something wrong with the
approach I've taken to writing the data to  I'm not sure if
it matters, but the zipped data is Unicode.

What would cause a zip file to not have a table of contents?  Is there
some way I can add a table of contents to a zip file using python?
Maybe there is some more fundamental problem with the data that is
making it seem like there is no table of contents?

Thanks in advance for your help.

More information about the Python-list mailing list