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

WinError 10060 #8

Closed
mikhailsirenko opened this issue Oct 8, 2023 · 6 comments
Closed

WinError 10060 #8

mikhailsirenko opened this issue Oct 8, 2023 · 6 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@mikhailsirenko
Copy link

mikhailsirenko commented Oct 8, 2023

Hi,

Thanks a lot for your work!

I'm trying to run the following piece and it results in: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

from gadm import GADMDownloader
downloader = GADMDownloader(version="4.0")
ad_level = 2
gdf = downloader.get_shape_data_by_country_name(country_name='Bulgaria', ad_level=ad_level)

Any ideas what went wrong? Thank you!

I'm aslo attaching a full error message:

{
	"name": "AttributeError",
	"message": "",
	"stack": "---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connection.py:203, in HTTPConnection._new_conn(self)
    202 try:
--> 203     sock = connection.create_connection(
    204         (self._dns_host, self.port),
    205         self.timeout,
    206         source_address=self.source_address,
    207         socket_options=self.socket_options,
    208     )
    209 except socket.gaierror as e:

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\util\\connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\util\\connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

The above exception was the direct cause of the following exception:

NewConnectionError                        Traceback (most recent call last)
File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connectionpool.py:790, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    789 # Make the request on the HTTPConnection object
--> 790 response = self._make_request(
    791     conn,
    792     method,
    793     url,
    794     timeout=timeout_obj,
    795     body=body,
    796     headers=headers,
    797     chunked=chunked,
    798     retries=retries,
    799     response_conn=response_conn,
    800     preload_content=preload_content,
    801     decode_content=decode_content,
    802     **response_kw,
    803 )
    805 # Everything went great!

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connectionpool.py:491, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    490         new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 491     raise new_e
    493 # conn.request() calls http.client.*.request, not the method in
    494 # urllib3.request. It also calls makefile (recv) on the socket.

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connectionpool.py:467, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    466 try:
--> 467     self._validate_conn(conn)
    468 except (SocketTimeout, BaseSSLError) as e:

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connectionpool.py:1092, in HTTPSConnectionPool._validate_conn(self, conn)
   1091 if conn.is_closed:
-> 1092     conn.connect()
   1094 if not conn.is_verified:

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connection.py:611, in HTTPSConnection.connect(self)
    610 sock: socket.socket | ssl.SSLSocket
--> 611 self.sock = sock = self._new_conn()
    612 server_hostname: str = self.host

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connection.py:218, in HTTPConnection._new_conn(self)
    217 except OSError as e:
--> 218     raise NewConnectionError(
    219         self, f\"Failed to establish a new connection: {e}\"
    220     ) from e
    222 # Audit hooks are only available in Python 3.8+

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000002BA26E83B20>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    485 try:
--> 486     resp = conn.urlopen(
    487         method=request.method,
    488         url=url,
    489         body=request.body,
    490         headers=request.headers,
    491         redirect=False,
    492         assert_same_host=False,
    493         preload_content=False,
    494         decode_content=False,
    495         retries=self.max_retries,
    496         timeout=timeout,
    497         chunked=chunked,
    498     )
    500 except (ProtocolError, OSError) as err:

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\connectionpool.py:844, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    842     new_e = ProtocolError(\"Connection aborted.\", new_e)
--> 844 retries = retries.increment(
    845     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    846 )
    847 retries.sleep()

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\urllib3\\util\\retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    514     reason = error or ResponseError(cause)
--> 515     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    517 log.debug(\"Incremented Retry for (url='%s'): %r\", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='geodata.ucdavis.edu', port=443): Max retries exceeded with url: /gadm/gadm4.0/gpkg/gadm40_BGR.gpkg (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002BA26E83B20>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\gadm\\gadm_downloader.py:72, in GADMDownloader.get_shape_data_by_country(self, country, ad_level)
     71 try:
---> 72     download_url(
     73         self._url_root_dir + data_path,
     74         abs_data_path,
     75     )
     76 except Exception as e:

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\gadm\\utils.py:23, in download_url(url, file_path)
     14 \"\"\"download file from url
     15 
     16 Parameters
   (...)
     21     local path of the file
     22 \"\"\"
---> 23 res0 = requests.head(url)
     24 assert \"Content-Length\" in res0.headers

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\api.py:100, in head(url, **kwargs)
     99 kwargs.setdefault(\"allow_redirects\", False)
--> 100 return request(\"head\", url, **kwargs)

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\api.py:59, in request(method, url, **kwargs)
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\sessions.py:703, in Session.send(self, request, **kwargs)
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\requests\\adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    517         raise SSLError(e, request=request)
--> 519     raise ConnectionError(e, request=request)
    521 except ClosedPoolError as e:

ConnectionError: HTTPSConnectionPool(host='geodata.ucdavis.edu', port=443): Max retries exceeded with url: /gadm/gadm4.0/gpkg/gadm40_BGR.gpkg (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002BA26E83B20>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
c:\\Users\\Mikhail\\My Drive\\0 Code\\havana\
otebooks\\tests.ipynb Cell 5 line 5
      <a href='vscode-notebook-cell:/c%3A/Users/Mikhail/My%20Drive/0%20Code/havana/notebooks/tests.ipynb#X11sZmlsZQ%3D%3D?line=1'>2</a> downloader = GADMDownloader(version=\"4.0\")
      <a href='vscode-notebook-cell:/c%3A/Users/Mikhail/My%20Drive/0%20Code/havana/notebooks/tests.ipynb#X11sZmlsZQ%3D%3D?line=3'>4</a> ad_level = 2
----> <a href='vscode-notebook-cell:/c%3A/Users/Mikhail/My%20Drive/0%20Code/havana/notebooks/tests.ipynb#X11sZmlsZQ%3D%3D?line=4'>5</a> gdf = downloader.get_shape_data_by_country_name(country_name='Bulgaria', ad_level=ad_level)

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\gadm\\gadm_downloader.py:110, in GADMDownloader.get_shape_data_by_country_name(self, country_name, ad_level)
    107     self._logger.error(f\"could not find data for {country_name}\")
    108     return None
--> 110 return self.get_shape_data_by_country(country, ad_level)

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\gadm\\gadm_downloader.py:77, in GADMDownloader.get_shape_data_by_country(self, country, ad_level)
     72     download_url(
     73         self._url_root_dir + data_path,
     74         abs_data_path,
     75     )
     76 except Exception as e:
---> 77     self._logger.error(f\"failed to fetch data for {country.common_name} with error {e}\")
     78     return None
     80 layers: List[str] = sorted(fiona.listlayers(abs_data_path))

File c:\\Users\\Mikhail\\miniconda3\\envs\\havana\\lib\\site-packages\\pycountry\\db.py:17, in Data.__getattr__(self, key)
     15 def __getattr__(self, key):
     16     if key not in self._fields:
---> 17         raise AttributeError
     18     return self._fields[key]

AttributeError: "
}
@xmba15
Copy link
Owner

xmba15 commented Oct 11, 2023

@mikhailsirenko thanks for the feedback. I'll take a look at this.

@thchilly
Copy link

@xmba15 I am getting the same error, running the following:


country_name = "Greece"
ad_level = 2
gdf = downloader.get_shape_data_by_country_name(country_name=country_name, ad_level=ad_level)

assert isinstance(gdf, gpd.GeoDataFrame)
gdf.plot()

Error message:

TimeoutError                              Traceback (most recent call last)
File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connection.py:200, in HTTPConnection._new_conn(self)
    199 try:
--> 200     sock = connection.create_connection(
    201         (self._dns_host, self.port),
    202         self.timeout,
    203         source_address=self.source_address,
    204         socket_options=self.socket_options,
    205     )
    206 except socket.gaierror as e:

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\util\connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\util\connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

The above exception was the direct cause of the following exception:

NewConnectionError                        Traceback (most recent call last)
File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connectionpool.py:790, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    789 # Make the request on the HTTPConnection object
--> 790 response = self._make_request(
    791     conn,
    792     method,
    793     url,
    794     timeout=timeout_obj,
    795     body=body,
    796     headers=headers,
    797     chunked=chunked,
    798     retries=retries,
    799     response_conn=response_conn,
    800     preload_content=preload_content,
    801     decode_content=decode_content,
    802     **response_kw,
    803 )
    805 # Everything went great!

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connectionpool.py:491, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    490         new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 491     raise new_e
    493 # conn.request() calls http.client.*.request, not the method in
    494 # urllib3.request. It also calls makefile (recv) on the socket.

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connectionpool.py:467, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    466 try:
--> 467     self._validate_conn(conn)
    468 except (SocketTimeout, BaseSSLError) as e:

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connectionpool.py:1092, in HTTPSConnectionPool._validate_conn(self, conn)
   1091 if conn.is_closed:
-> 1092     conn.connect()
   1094 if not conn.is_verified:

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connection.py:604, in HTTPSConnection.connect(self)
    603 sock: socket.socket | ssl.SSLSocket
--> 604 self.sock = sock = self._new_conn()
    605 server_hostname: str = self.host

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connection.py:215, in HTTPConnection._new_conn(self)
    214 except OSError as e:
--> 215     raise NewConnectionError(
    216         self, f"Failed to establish a new connection: {e}"
    217     ) from e
    219 return sock

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000021D368FBEB0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    485 try:
--> 486     resp = conn.urlopen(
    487         method=request.method,
    488         url=url,
    489         body=request.body,
    490         headers=request.headers,
    491         redirect=False,
    492         assert_same_host=False,
    493         preload_content=False,
    494         decode_content=False,
    495         retries=self.max_retries,
    496         timeout=timeout,
    497         chunked=chunked,
    498     )
    500 except (ProtocolError, OSError) as err:

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\connectionpool.py:844, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    842     new_e = ProtocolError("Connection aborted.", new_e)
--> 844 retries = retries.increment(
    845     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    846 )
    847 retries.sleep()

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\urllib3\util\retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    514     reason = error or ResponseError(cause)
--> 515     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    517 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='geodata.ucdavis.edu', port=443): Max retries exceeded with url: /gadm/gadm4.0/gpkg/gadm40_GRC.gpkg (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021D368FBEB0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
File ~\.conda\envs\sci-python38-matlab\lib\site-packages\gadm\gadm_downloader.py:72, in GADMDownloader.get_shape_data_by_country(self, country, ad_level)
     71 try:
---> 72     download_url(
     73         self._url_root_dir + data_path,
     74         abs_data_path,
     75     )
     76 except Exception as e:

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\gadm\utils.py:23, in download_url(url, file_path)
     14 """download file from url
     15 
     16 Parameters
   (...)
     21     local path of the file
     22 """
---> 23 res0 = requests.head(url)
     24 assert "Content-Length" in res0.headers

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\api.py:100, in head(url, **kwargs)
     99 kwargs.setdefault("allow_redirects", False)
--> 100 return request("head", url, **kwargs)

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\api.py:59, in request(method, url, **kwargs)
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\sessions.py:703, in Session.send(self, request, **kwargs)
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\requests\adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    517         raise SSLError(e, request=request)
--> 519     raise ConnectionError(e, request=request)
    521 except ClosedPoolError as e:

ConnectionError: HTTPSConnectionPool(host='geodata.ucdavis.edu', port=443): Max retries exceeded with url: /gadm/gadm4.0/gpkg/gadm40_GRC.gpkg (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021D368FBEB0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[15], line 5
      3 country_name = "Greece"
      4 ad_level = 2
----> 5 gdf = downloader.get_shape_data_by_country_name(country_name=country_name, ad_level=ad_level)
      7 assert isinstance(gdf, gpd.GeoDataFrame)
      8 gdf.plot()

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\gadm\gadm_downloader.py:110, in GADMDownloader.get_shape_data_by_country_name(self, country_name, ad_level)
    107     self._logger.error(f"could not find data for {country_name}")
    108     return None
--> 110 return self.get_shape_data_by_country(country, ad_level)

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\gadm\gadm_downloader.py:77, in GADMDownloader.get_shape_data_by_country(self, country, ad_level)
     72     download_url(
     73         self._url_root_dir + data_path,
     74         abs_data_path,
     75     )
     76 except Exception as e:
---> 77     self._logger.error(f"failed to fetch data for {country.common_name} with error {e}")
     78     return None
     80 layers: List[str] = sorted(fiona.listlayers(abs_data_path))

File ~\.conda\envs\sci-python38-matlab\lib\site-packages\pycountry\db.py:17, in Data.__getattr__(self, key)
     15 def __getattr__(self, key):
     16     if key not in self._fields:
---> 17         raise AttributeError
     18     return self._fields[key]

AttributeError: ```

@xmba15
Copy link
Owner

xmba15 commented Oct 14, 2023

@mikhailsirenko @thchilly
Does the issue still persist now?
I just tested today, and the geographic data for the country can still be downloaded.

This library fetches data from a public storage, so it may have some bandwidth constraints.
The issue might stem from your internet connection.

I can implement a logic in which we try to download multiple times before giving up but that won't suffice if the problem lies in users' internet connection.

@xmba15
Copy link
Owner

xmba15 commented Oct 14, 2023

One more possibility is that the public storage site blocked this library's fetching data as a scraper.
I fixed this in this PR: #9

Can you try with the newest version now?
python3 -m pip install gadm==v0.0.4

@xmba15 xmba15 self-assigned this Oct 14, 2023
@xmba15 xmba15 added the help wanted Extra attention is needed label Oct 14, 2023
@mikhailsirenko
Copy link
Author

One more possibility is that the public storage site blocked this library's fetching data as a scraper. I fixed this in this PR: #9

Can you try with the newest version now? python3 -m pip install gadm==v0.0.4

Works like charm! Thanks @xmba15, you're the best!

@thchilly
Copy link

Thanks @xmba15, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants