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

廉价感情. 提交于 2020-01-13 08:15:26

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/17664262/python-zipfile-module-erroneously-thinks-i-have-a-zipfile-that-spans-multiple-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!