10
votes

While extracting zipfile in to my google drive using colaboratory, I got an error saying zipfile read error. How to fix it?

I'm trying to unzip file using the following python 3 script:

from google.colab import drive
drive.mount('/gdrive')

!unzip '/gdrive/My Drive/file.zip' -d '/gdrive/My Drive/Destination/'

After extracting 4 files from the zip I got this error

error:  zipfile read error
2
Im having the same problem. Did you ever solve this - fontno
Same issue, I'm extracting file from drive in colab local storage, after extracting 2628/10000 images, it causes zip file error and terminates. I tried various alternatives but no solution. - Aniket Velhankar
Encountered the same issue, unmounted and remounted drive worked for me - hangc
Any fix? I am facing the same issue. - yudhiesh
August 2020, still having this problem with 25 GB zip file - CrmXao

2 Answers

0
votes

I was unable to resolve the why, but was able to get put a band-aid on the problem (along with some process informatin) with the following Python code:

from zipfile import ZipFile

# Get information about how much you're decompressing
zf = ZipFile('./gdrive/My Drive/poizon/data/images.zip')
uncompress_size = sum((file.file_size for file in zf.infolist()))
print('uncompressed_size',uncompress_size/1e6)

# Loop through all files attempting to decompress each individually
extracted_size = 0
for file in zf.infolist():
    extracted_size += file.file_size
    print ("%s %%" % (extracted_size * 100/uncompress_size))
    try:
      zf.extract(file)
    except:
      continue
0
votes

Try this:

import zipfile
import os

file_location = 'file_path/file_name.zip'

with zipfile.ZipFile(file_location, 'r') as zip_ref:
    zip_ref.extractall('/content') # Replace '/content' with where you want to extract all files.

I hope it will not show any error.