Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadZipFile error on google colab #2

Open
JustinGOSSES opened this issue Jun 14, 2021 · 1 comment
Open

BadZipFile error on google colab #2

JustinGOSSES opened this issue Jun 14, 2021 · 1 comment

Comments

@JustinGOSSES
Copy link

Interesting project, read the paper as well.

When trying to run the google colab notebook Estimate_per_image_in_folder.ipynb , I had an error unzipping the snap images.

Specifically, talking about this line

image_dir = 'snap_images'+os.sep+'data'

url = 'https://drive.google.com/file/d/11xd3HWcfEE_yMYcSsr1StFFPSdXNAjKH/view?usp=sharing'		
if not os.path.isdir(os.path.join(os.getcwd(),image_dir)):
  file_id = '11xd3HWcfEE_yMYcSsr1StFFPSdXNAjKH' 
  destination = 'snap_images.zip'
  download_file_from_google_drive(file_id, destination)	
  print('download complete ... unzipping')	
  zip_ref = zipfile.ZipFile(destination, 'r')
  zip_ref.extractall(os.getcwd())
  zip_ref.close()
  os.remove(destination)

Which gave me this error:

download complete ... unzipping
---------------------------------------------------------------------------
BadZipFile                                Traceback (most recent call last)
<ipython-input-34-091b21f1e2e4> in <module>()
      7   download_file_from_google_drive(file_id, destination)
      8   print('download complete ... unzipping')
----> 9   zip_ref = zipfile.ZipFile(destination, 'r')
     10   zip_ref.extractall(os.getcwd())
     11   zip_ref.close()

1 frames
/usr/lib/python3.7/zipfile.py in _RealGetContents(self)
   1323             raise BadZipFile("File is not a zip file")
   1324         if not endrec:
-> 1325             raise BadZipFile("File is not a zip file")
   1326         if self.debug > 1:
   1327             print(endrec)

BadZipFile: File is not a zip file

I've restarted the kernal a couple different times and got the same error pattern.

When I downloaded the snap_images.zip file locally from colab to insect it, I saw the following behavior. When I double click to unzip the zip file, it appends ".cpgz" to the end. When I doubleclick that file, it adds the ".zip" file ending pack. Basically, I go in a circle.

I've searched around a bit for similar problems and it seems like there are a variety of potential problems. This one describes pretty well the pattern of trying to open it locally https://osxdaily.com/2013/02/13/open-zip-cpgz-file/ .

I'll try to investigate more later, but figured I'd start this issue now as any solution might be relevant for others as well.

@JustinGOSSES JustinGOSSES changed the title Zip error on google colab BadZipFile error on google colab Jun 14, 2021
@dbuscombe-usgs
Copy link
Member

Thanks for making me aware -- Apologies, this is old code and I have not checked it in some time. I need to switch to pooch or s3 or similar for data files - the google drive was my 'circa 2018' solution and its not a good solution for a few reasons. Hopefully will re-implement soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants