-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Hi,
I was following Earth lab's Intro to earth data science textbook and in Section 2, chapter-5 while running the codes for vector files, I am getting BadZipFile
errors. This problem seems to be with all files from the Natural Earth webpage. I am able to download the zip file separately but using get_data
function is giving an error.
Here is the code I am running:
# Import packages
import os
os.environ['USE_PYGEOS'] = '0'
import matplotlib.pyplot as plt
import geopandas as gpd
import earthpy as et
link = 'https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_boundary_lines_land.zip'
# Download the data and set working directory
et.data.get_data(url=link)
# Set working directory - earthpy creates earth-analytics for you in your home dir
os.chdir(os.path.join(et.io.HOME, 'earth-analytics'))
I am getting following error:
Downloading from https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_boundary_lines_land.zip
BadZipFile Traceback (most recent call last)
Cell In[17], line 3
1 link = 'https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_boundary_lines_land.zip'
2 # Download the data and set working directory
----> 3 et.data.get_data(url=link)
5 # Set working directory - earthpy creates earth-analytics for you in your home dir
6 os.chdir(os.path.join(et.io.HOME, 'earth-analytics'))File ~/miniconda3/envs/earth-analytics-python/lib/python3.8/site-packages/earthpy/io.py:247, in Data.get_data(self, key, url, replace, verbose)
240 if kind not in ALLOWED_FILE_TYPES:
241 raise ValueError(
242 "kind must be one of {}, got {}".format(
243 ALLOWED_FILE_TYPES, kind
244 )
245 )
--> 247 this_path = self._download(
248 url=url,
249 path=os.path.join(this_root, name),
250 kind=kind,
251 replace=replace,
252 verbose=verbose,
253 )
254 data_paths.append(this_path)
255 if len(data_paths) == 1:File ~/miniconda3/envs/earth-analytics-python/lib/python3.8/site-packages/earthpy/io.py:300, in Data._download(self, url, path, kind, replace, verbose)
298 f.write(r.content)
299 else:
--> 300 self._download_and_extract(path, r, kind, verbose)
301 return pathFile ~/miniconda3/envs/earth-analytics-python/lib/python3.8/site-packages/earthpy/io.py:328, in Data._download_and_extract(self, path, r, kind, verbose)
326 file_like_object = io.BytesIO(r.content)
327 if kind == "zip":
--> 328 archive = zipfile.ZipFile(file_like_object)
329 if kind == "tar":
330 archive = tarfile.open(fileobj=file_like_object)File ~/miniconda3/envs/earth-analytics-python/lib/python3.8/zipfile.py:1269, in ZipFile.init(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
1267 try:
1268 if mode == 'r':
-> 1269 self._RealGetContents()
1270 elif mode in ('w', 'x'):
1271 # set the modified flag so central directory gets written
1272 # even if no files are added to the archive
1273 self._didModify = TrueFile ~/miniconda3/envs/earth-analytics-python/lib/python3.8/zipfile.py:1336, in ZipFile._RealGetContents(self)
1334 raise BadZipFile("File is not a zip file")
1335 if not endrec:
-> 1336 raise BadZipFile("File is not a zip file")
1337 if self.debug > 1:
1338 print(endrec)BadZipFile: File is not a zip file
Hope this will be helpful for you in solving the issue.
Thank you
Girish