Gaierror when accessing regionmask data

Hi! I’m using us-central1-b.gcp.pangeo.io to process CMIP6 data. When I try using the regionmask package:

!pip install git+https://github.com/regionmask/regionmask
import regionmask
basins = regionmask.defined_regions.natural_earth.ocean_basins_50

an error message appears:

gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:
URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

I was searching for how to resolve the error and it seems firewall restrictions can play a role. I wonder if the regionmask URL is restricted? Or is it something I have to configure on my end? Thanks!

1 Like

Thanks for sharing.

I tried to reproduce this and got a similar error. Looking at the stack trace, I saw this

/srv/conda/envs/notebook/lib/python3.8/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naciscdn.org/naturalearth/50m/physical/ne_50m_geography_marine_polys.zip
  warnings.warn('Downloading: {}'.format(url), DownloadWarning)
---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1353             try:
-> 1354                 h.request(req.get_method(), req.selector, req.data, headers,
   1355                           encode_chunked=req.has_header('Transfer-encoding'))

/srv/conda/envs/notebook/lib/python3.8/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1251         """Send a complete request to the server."""
-> 1252         self._send_request(method, url, body, headers, encode_chunked)
   1253 

/srv/conda/envs/notebook/lib/python3.8/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1297             body = _encode(body, 'body')
-> 1298         self.endheaders(body, encode_chunked=encode_chunked)
   1299 

/srv/conda/envs/notebook/lib/python3.8/http/client.py in endheaders(self, message_body, encode_chunked)
   1246             raise CannotSendHeader()
-> 1247         self._send_output(message_body, encode_chunked=encode_chunked)
   1248 

/srv/conda/envs/notebook/lib/python3.8/http/client.py in _send_output(self, message_body, encode_chunked)
   1006         del self._buffer[:]
-> 1007         self.send(msg)
   1008 

/srv/conda/envs/notebook/lib/python3.8/http/client.py in send(self, data)
    946             if self.auto_open:
--> 947                 self.connect()
    948             else:

/srv/conda/envs/notebook/lib/python3.8/http/client.py in connect(self)
   1413 
-> 1414             super().connect()
   1415 

/srv/conda/envs/notebook/lib/python3.8/http/client.py in connect(self)
    917         """Connect to the host and port specified in __init__."""
--> 918         self.sock = self._create_connection(
    919             (self.host,self.port), self.timeout, self.source_address)

/srv/conda/envs/notebook/lib/python3.8/socket.py in create_connection(address, timeout, source_address)
    786     err = None
--> 787     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    788         af, socktype, proto, canonname, sa = res

/srv/conda/envs/notebook/lib/python3.8/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    917     addrlist = []
--> 918     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    919         af, socktype, proto, canonname, sa = res

gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
/tmp/ipykernel_1044/4167181885.py in <module>
      1 import regionmask
----> 2 basins = regionmask.defined_regions.natural_earth.ocean_basins_50

/srv/conda/envs/notebook/lib/python3.8/site-packages/regionmask/defined_regions/natural_earth.py in ocean_basins_50(self)
    264             )
    265 
--> 266             regs = _obtain_ne(**opt)
    267 
    268             # NOTE: naturalearth includes duplicate names

/srv/conda/envs/notebook/lib/python3.8/site-packages/regionmask/defined_regions/natural_earth.py in _obtain_ne(resolution, category, name, title, names, abbrevs, numbers, coords, query, combine_coords)
     79 
     80     # maybe download natural_earth feature and return filename
---> 81     shpfilename = shapereader.natural_earth(resolution, category, name)
     82 
     83     # read the file with geopandas

/srv/conda/envs/notebook/lib/python3.8/site-packages/cartopy/io/shapereader.py in natural_earth(resolution, category, name)
    280     format_dict = {'config': config, 'category': category,
    281                    'name': name, 'resolution': resolution}
--> 282     return ne_downloader.path(format_dict)
    283 
    284 

/srv/conda/envs/notebook/lib/python3.8/site-packages/cartopy/io/__init__.py in path(self, format_dict)
    201         else:
    202             # we need to download the file
--> 203             result_path = self.acquire_resource(target_path, format_dict)
    204 
    205         return result_path

/srv/conda/envs/notebook/lib/python3.8/site-packages/cartopy/io/shapereader.py in acquire_resource(self, target_path, format_dict)
    335         url = self.url(format_dict)
    336 
--> 337         shapefile_online = self._urlopen(url)
    338 
    339         zfh = ZipFile(io.BytesIO(shapefile_online.read()), 'r')

/srv/conda/envs/notebook/lib/python3.8/site-packages/cartopy/io/__init__.py in _urlopen(self, url)
    240         """
    241         warnings.warn('Downloading: {}'.format(url), DownloadWarning)
--> 242         return urlopen(url)
    243 
    244     @staticmethod

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
    523 
    524         sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 525         response = self._open(req, data)
    526 
    527         # post-process response

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in _open(self, req, data)
    540 
    541         protocol = req.type
--> 542         result = self._call_chain(self.handle_open, protocol, protocol +
    543                                   '_open', req)
    544         if result:

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    500         for handler in handlers:
    501             func = getattr(handler, meth_name)
--> 502             result = func(*args)
    503             if result is not None:
    504                 return result

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in https_open(self, req)
   1395 
   1396         def https_open(self, req):
-> 1397             return self.do_open(http.client.HTTPSConnection, req,
   1398                 context=self._context, check_hostname=self._check_hostname)
   1399 

/srv/conda/envs/notebook/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1355                           encode_chunked=req.has_header('Transfer-encoding'))
   1356             except OSError as err: # timeout error
-> 1357                 raise URLError(err)
   1358             r = h.getresponse()
   1359         except:

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

It looks like regionmask is trying to download the file https://naciscdn.org/naturalearth/50m/physical/ne_50m_geography_marine_polys.zip. As you can see for yourself by following that link, the file is not there at the moment.

I would definitely raise an issue on the regionmask issue tracker.

1 Like

Right, I hadn’t noticed this :sweat_smile: Will raise an issue with regionmask, thank you!

Thanks again for the reply! It seems like this URL is updated with the latest version of cartopy. I tried installing it on Pangeo Cloud:

!pip install git+https://github.com/SciTools/cartopy.git
!pip install cartopy --upgrade

either code results in the ff error:

 ERROR: Failed building wheel for cartopy
Failed to build cartopy
ERROR: Could not build wheels for cartopy which use PEP 517 and cannot be installed directly

When I use !conda update -c conda-forge cartopy eventually it asks me to input `[y/n]’:

The following packages will be UPDATED:

  ca-certificates                      2020.12.5-ha878542_0 --> 2021.5.30-ha878542_0
  certifi                          2020.12.5-py38h578d9bd_1 --> 2021.5.30-py38h578d9bd_0
  openssl                                 1.1.1i-h7f98852_0 --> 1.1.1k-h7f98852_0


Proceed ([y]/n)? 

which is tricky to do with a Jupyter notebook. Is there a recommended way to update cartopy? Thanks!

When I use !conda update -c conda-forge cartopy eventually it asks me to input `[y/n]’: … which is tricky to do with a Jupyter notebook.

@jdldeauna, I believe you can use the -y or --yes option to bypass these confirmation requests.

Does

!conda update -c conda-forge --yes cartopy

work for you in a notebook?

1 Like

It worked, thank you!

1 Like