Python zipfile 模块错误地认为我有一个跨越多个磁盘的 zipfile,抛出 BadZipfile 错误 [英] Python zipfile module erroneously thinks I have a zipfile that spans multiple disks, throws BadZipfile error
问题描述
我有一个 1.4GB 的 zip 文件,我正在尝试依次让每个成员产生.zipfile 模块不断抛出 BadZipfile 异常,说明
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:不支持跨越多个磁盘的 zipfile".
"zipfile.BadZipfile: zipfiles that span multiple disks are not supported".
这是我的代码:
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 上都尝试过,结果相同.非常感谢任何帮助.
I'm using Python 2.7.3. I tried on both Windows 8 and ubuntu with the same result. Any help very much appreciated.
推荐答案
尽管我使用的是 python 3.4,但我在类似文件上遇到了同样的错误
I get the same error on a similar file although I am using python 3.4
可以通过编辑 zipfile.py 源代码中的第 205 行来修复它:
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")
到:
if diskno != 0 or disks > 1:
希望能帮到你
这篇关于Python zipfile 模块错误地认为我有一个跨越多个磁盘的 zipfile,抛出 BadZipfile 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!