Products Resources Support About Us

Zipfile throws error in python 2.7


Hi Folks,

I seem to be getting a ‘BadZipfile’ error when I try to execute the following against any zip file.

import zipfile
if __name__=='__main__':
    zipped_path = './'
    z = zipfile.ZipFile(zipped_path)

Gives the following -

Traceback (most recent call last):
  File "", line 5, in <module>'zipfile.ZipFile(zipped_path)')
  File "/etc/rocket/python-2017-04-12-py27/lib/python2.7/", line 1238, in run
    Pdb().run(statement, globals, locals)
  File "/etc/rocket/python-2017-04-12-py27/lib/python2.7/", line 400, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "/test_python/", line 766, in __init__
  File "/test_python/", line 807, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

Here is some info about my environment -



>python --version
Python 2.7.6

The same zip file ( is read properly with Rocket’s unzip under USS. I looked into why zipfile was throwing the error and it looks like its comparing a string that its reading from ‘’ that is represented as ASCII with a string hardcoded in zipfile that is represented as EBCDIC. Here is some output from the debugger that illustrates what I mean -

> <string>(1)<module>()
(Pdb) b zipfile:219
Breakpoint 1 at /test_python/
(Pdb) c
> /test_python/
-> if (len(data) == sizeEndCentDir and
(Pdb) data[0]
(Pdb) data[0].encode('hex')
(Pdb) stringEndArchive[0]
(Pdb) stringEndArchive[0].encode('hex')

Any recommendations on how I can fix this?



Have you tried with the newer port Python 2.7.13 ?

This works with ASCII internally rather than with EBCDIC.

There is a chance that this fixes the problem.


Thanks, that worked!