我有一个 1.4GB 的 zip 文件,正在尝试连续生成每个成员。 zipfile 模块不断抛出 BadZipfile 异常,指出
“zipfile.BadZipfile:不支持跨多个磁盘的 zip 文件”。
这是我的代码:
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'))
我正在使用Python 2.7.3。我在 Windows 8 和 ubuntu 上都尝试过,结果相同。非常感谢任何帮助。
尽管我使用的是 python 3.4,但我在类似的文件上遇到了相同的错误
可以通过编辑 zipfile.py 源代码中的第 205 行来修复它:
if diskno != 0 or disks != 1:
raise BadZipFile("zipfiles that span multiple disks are not supported")
to:
if diskno != 0 or disks > 1:
希望这可以帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)