[解压缩该文件时会出现此错误:无效的zip文件不是zip文件

问题描述 投票:0回答:1

我想提取压缩文件。文件名是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个回答
0
投票

您的代码对我来说很好。您确定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.
© www.soinside.com 2019 - 2024. All rights reserved.