0

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")
help-info.de
  • 6,695
  • 16
  • 39
  • 41

1 Answers1

0

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.
pmqs
  • 3,066
  • 2
  • 13
  • 22
  • i am using window and working on Diabetic retinopathy detection. the dataset avialable in kaggle is in this form test.zip.001 now i don't know whether it is a zip file or not? – dildar ali Dec 06 '19 at 19:20
  • Is the file available on the web somewhere we can access it? – pmqs Dec 06 '19 at 19:26
  • this is my code https://colab.research.google.com/drive/1dM8vgeI-SBFi_LcrU5Wbmep0JHxcV6Fl# and link for data is :https://www.kaggle.com/c/diabetic-retinopathy-detection/data – dildar ali Dec 07 '19 at 18:20
  • I see in the kaggle linke it says "Due to the extremely large size of this dataset, we have separated the files into multi-part archives. We recommend using 7zip or keka to extract". You need to combine the 7 parts of test.zip files before you can read it. Try 7zip. – pmqs Dec 07 '19 at 22:13
  • sir do you have any code for unziping this file in google colab using 7zip – dildar ali Dec 08 '19 at 06:01
  • Never heardrd of colab, but a quick search found these links https://stackoverflow.com/questions/49955814/unzip-a-7z-file-in-google-collab and https://forums.fast.ai/t/unzipping-tar-7z-files-in-google-collab-notebook/14857 – pmqs Dec 08 '19 at 09:11