Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python zipfile module erroneously thinks I have a zipfile that spans multiple disks, throws BadZipfile error

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.

like image 452
user1541702 Avatar asked Jul 15 '13 21:07

user1541702


2 Answers

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
like image 61
Milind Prajapat Avatar answered Sep 30 '22 00:09

Milind Prajapat


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

like image 37
Josselin Avatar answered Sep 30 '22 00:09

Josselin