【问题标题】:while unzipping this file it give me this error : bad zip-file file is not a zip file解压缩此文件时,出现此错误:损坏的 zip 文件不是 zip 文件
【发布时间】:2019-12-06 17:16:23
【问题描述】:

我想提取 zip 文件。文件名为test.zip.001。 我正在尝试解压缩此文件,但它给了我这个错误:

错误的 ZipFile:文件不是 zip 文件

这是我的代码:

from zipfile import ZipFile
file_name="test.zip.004"
with ZipFile(file_name,'r') as zip:
    zip.extractall()
    print("Done")

【问题讨论】:

    标签: python unzip


    【解决方案1】:

    您的代码对我来说很好用。您确定test.zip.004 实际上是一个有效的 zip 文件吗?

    如果您在 Linux 上运行,或者可以访问命令行 unzip 命令,请尝试测试该文件是否有效。

    # Check that it is valid
    $ unzip -t test.zip.004
    Archive:  test.zip.004
        testing: abc                      OK
    No errors detected in compressed data of test.zip.004.
    
    # Corrupt the zip file
    $ echo xxx >test.zip.004
    
    # unzip spots the corruption
    $ unzip -t test.zip.004
    Archive:  test.zip.004
      End-of-central-directory signature not found.  Either this file is not
      a zipfile, or it constitutes one disk of a multi-part archive.  In the
      latter case the central directory and zipfile comment will be found on
      the last disk(s) of this archive.
    unzip:  cannot find zipfile directory in one of test.zip.004 or
            test.zip.004.zip, and cannot find test.zip.004.ZIP, period.
    

    【讨论】:

    • 我正在使用 window 并致力于糖尿病视网膜病变检测。 kaggle 中可用的数据集是这种形式 test.zip.001 现在我不知道它是否是 zip 文件?
    • 该文件在网络上我们可以访问的地方可用吗?
    • 我在 kaggle 链接中看到它说“由于此数据集的大小非常大,我们已将文件分成多部分存档。我们建议使用 7zip 或 keka 进行提取”。您需要将 test.zip 文件的 7 个部分组合起来才能阅读。试试 7zip。
    • 先生,您有任何代码可以在 google colab 中使用 7zip 解压缩此文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多