简体   繁体   中英

while unzipping this file it give me this error : bad zip-file file is not a zip file

I want to extract zip-file. file name is test.zip.001 . I am trying to unzip this file but it gives me this error:

bad ZipFile: File is not a zip file

This is my code:

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

Your code works fine for me. Are you sure that test.zip.004 is actually a valid zip file?

If you are running on Linux, or have access to the commandline unzip command, try testing that the file is valid.

# 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM