11
votes

I have a 1.4GB zip file and am trying to yield each member in succession. The zipfile module keeps throwing a BadZipfile exception, stating that

"zipfile.BadZipfile: zipfiles that span multiple disks are not supported".

Here is my code:

import zipfile

def iterate_members(zip_file_like_object):
  zflo = zip_file_like_object
  assert zipfile.is_zipfile(zflo) # Here is where the error happens.
  # If I comment out the assert, the same error gets thrown on this next line:
  with zipfile.ZipFile(zflo) as zip:
    members = zip.namelist()
    for member in members:
      yield member

fn = "filename.zip"
iterate_members(open(fn, 'rb'))

I'm using Python 2.7.3. I tried on both Windows 8 and ubuntu with the same result. Any help very much appreciated.

2
Can you post the zip file (or a link to it)? The code that leads up to this error is pretty straightforward; it checks whether the file header declares more than one disk or the disk number of the file to be anything other than zero. - phihag
Thanks phihag. Unfortunately I cannot post the file as it contains confidential client data. - user1541702
Well, can you generate a zip file with large test data that still shows the problem? - phihag
Probably depends more on the software used to create the .zip. I just had this problem with a 500MB .zip from a customer. Unpacked it and repacked (obviously with a different zip tool than my customer) and it works. The repacked file is even bigger due to less compression. So, size does not seem to be all that matters. - Adrian W
python3.7 can be run with a file while python3.6 can't for me. - Lion Lai

2 Answers

15
votes

I get the same error on a similar file although I am using python 3.4

Was able to fix it by editing line 205 in zipfile.py source code:

if diskno != 0 or disks != 1:
    raise BadZipFile("zipfiles that span multiple disks are not supported")

to:

if diskno != 0 or disks > 1:

Hope this helps

1
votes

Quick Fix, Install zipfile38 using:

pip install zipfile38

And use it in the code same as you are doing before

import zipfile38 as zipfile
#your code goes here