Merge branch 'feature/documentation-restructuring' of github.com:CLIM… #1187
8 fail, 700 pass in 12m 32s
Annotations
Check warning on line 0 in climada.engine.test.test_impact_data.TestEmdatProcessing
github-actions / Core / Unit Test Results (3.9)
test_emdat_impact_event_2018 (climada.engine.test.test_impact_data.TestEmdatProcessing) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6becb9e50>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb6bf099730>
method = 'GET'
url = '/v2/countries/USA/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb6bf099730>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb6bead4ac0>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb6becb99d0>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6becb9e50>
err = timeout('The read operation timed out')
url = '/v2/countries/USA/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.engine.test.test_impact_data.TestEmdatProcessing testMethod=test_emdat_impact_event_2018>
def test_emdat_impact_event_2018(self):
"""test emdat_impact_event event impact data extraction, version 2018"""
> df = im_d.emdat_impact_event(
EMDAT_TEST_CSV,
countries=["Bangladesh", "USA"],
hazard="Drought",
year_range=[2015, 2017],
reference_year=2017,
version=2018,
)
climada/engine/test/test_impact_data.py:122:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/impact_data.py:1076: in emdat_impact_event
df_data["impact_scaled"] = scale_impact2refyear(
climada/engine/impact_data.py:896: in scale_impact2refyear
gdp_ref[country] = gdp(country, reference_year)[1]
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb6becb99d0>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.engine.test.test_impact_data.TestEmdatProcessing
github-actions / Core / Unit Test Results (3.9)
test_emdat_impact_event_2020 (climada.engine.test.test_impact_data.TestEmdatProcessing) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6be7189d0>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb6be718ca0>
method = 'GET'
url = '/v2/countries/USA/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb6be718ca0>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb6bf03fc40>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb6be718760>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6be7189d0>
err = timeout('The read operation timed out')
url = '/v2/countries/USA/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.engine.test.test_impact_data.TestEmdatProcessing testMethod=test_emdat_impact_event_2020>
def test_emdat_impact_event_2020(self):
"""test emdat_impact_event event impact data extraction, version 2020"""
> df = im_d.emdat_impact_event(
EMDAT_TEST_CSV,
countries=["Bangladesh", "USA"],
hazard="Drought",
year_range=[2015, 2017],
reference_year=2000,
version=2020,
)
climada/engine/test/test_impact_data.py:146:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/impact_data.py:1076: in emdat_impact_event
df_data["impact_scaled"] = scale_impact2refyear(
climada/engine/impact_data.py:896: in scale_impact2refyear
gdp_ref[country] = gdp(country, reference_year)[1]
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb6be718760>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.entity.exposures.test.test_litpop.TestLitPop
github-actions / Core / Unit Test Results (3.9)
test_get_total_value_per_country_nfw (climada.entity.exposures.test.test_litpop.TestLitPop) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb682ba3ca0>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb682a24ca0>
method = 'GET'
url = '/v2/countries/POL/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb682a24ca0>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb689c58640>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb683d0d850>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb682ba3ca0>
err = timeout('The read operation timed out')
url = '/v2/countries/POL/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.entity.exposures.test.test_litpop.TestLitPop testMethod=test_get_total_value_per_country_nfw>
def test_get_total_value_per_country_nfw(self):
"test _get_total_value_per_country get number for pc of Poland"
> value = lp._get_total_value_per_country("POL", "nfw", 2015)
climada/entity/exposures/test/test_litpop.py:401:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/litpop/litpop.py:1050: in _get_total_value_per_country
gdp_value = u_fin.gdp(cntry_iso3a, reference_year)[1]
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb683d0d850>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.entity.exposures.test.test_litpop.TestLitPop
github-actions / Core / Unit Test Results (3.9)
test_get_total_value_per_country_pc (climada.entity.exposures.test.test_litpop.TestLitPop) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb683bcde50>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb683bcdf70>
method = 'GET'
url = '/v2/countries/POL/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb683bcdf70>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb683ba4f40>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb683bccf40>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb683bcde50>
err = timeout('The read operation timed out')
url = '/v2/countries/POL/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.entity.exposures.test.test_litpop.TestLitPop testMethod=test_get_total_value_per_country_pc>
def test_get_total_value_per_country_pc(self):
"test _get_total_value_per_country get number for pc of Poland"
> value = lp._get_total_value_per_country("POL", "pc", 2015)
climada/entity/exposures/test/test_litpop.py:396:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/entity/exposures/litpop/litpop.py:1037: in _get_total_value_per_country
return u_fin.world_bank_wealth_account(
climada/util/finance.py:436: in world_bank_wealth_account
gdp_year, gdp0_val = gdp(cntry_iso, np.max(years))
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb683bccf40>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.util.test.test_finance.TestWBData
github-actions / Core / Unit Test Results (3.9)
test_gdp_sxm_2010_pass (climada.util.test.test_finance.TestWBData) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6814d2310>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb6814d23a0>
method = 'GET'
url = '/v2/countries/SXM/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb6814d23a0>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb6820bd4c0>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb681457040>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6814d2310>
err = timeout('The read operation timed out')
url = '/v2/countries/SXM/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.util.test.test_finance.TestWBData testMethod=test_gdp_sxm_2010_pass>
def test_gdp_sxm_2010_pass(self):
"""Test gdp function Sint Maarten."""
# If World Bank input data changes, make sure to set ref_year to a year where
# no data is available so that the next available data point has to be selected.
ref_year = 2010
with self.assertLogs("climada.util.finance", level="INFO") as cm:
> gdp_year, gdp_val = gdp("SXM", ref_year)
climada/util/test/test_finance.py:108:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb681457040>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.util.test.test_finance.TestWBData
github-actions / Core / Unit Test Results (3.9)
test_wb_esp_1950_pass (climada.util.test.test_finance.TestWBData) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb680f1e820>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb681420e20>
method = 'GET'
url = '/v2/countries/ESP/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb681420e20>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb682046a00>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb680f1e460>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb680f1e820>
err = timeout('The read operation timed out')
url = '/v2/countries/ESP/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.util.test.test_finance.TestWBData testMethod=test_wb_esp_1950_pass>
def test_wb_esp_1950_pass(self):
"""Test world_bank function Sint Maarten."""
ref_year = 1950
> wb_year, wb_val = world_bank("ESP", ref_year, "NY.GDP.MKTP.CD")
climada/util/test/test_finance.py:133:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb680f1e460>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.util.test.test_finance.TestWBWealthAccount
github-actions / Core / Unit Test Results (3.9)
test_pca_CUB_2015_pass (climada.util.test.test_finance.TestWBWealthAccount) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6815c2a30>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb681dd64f0>
method = 'GET'
url = '/v2/countries/CUB/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb681dd64f0>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb682046640>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb680befaf0>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb6815c2a30>
err = timeout('The read operation timed out')
url = '/v2/countries/CUB/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.util.test.test_finance.TestWBWealthAccount testMethod=test_pca_CUB_2015_pass>
def test_pca_CUB_2015_pass(self):
"""Test Processed Capital value Cuba 2015 (missing value)."""
ref_year = 2015
cntry_iso = "CUB"
> wb_year, wb_val, q = world_bank_wealth_account(cntry_iso, ref_year, no_land=1)
climada/util/test/test_finance.py:228:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/finance.py:423: in world_bank_wealth_account
gdp_year, gdp_val = gdp(cntry_iso, ref_year)
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb680befaf0>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout
Check warning on line 0 in climada.util.test.test_finance.TestWBWealthAccount
github-actions / Core / Unit Test Results (3.9)
test_tow_IND_1985_pass (climada.util.test.test_finance.TestWBWealthAccount) failed
tests_xml/tests.xml [took 30s]
Raw output
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb661a4cbe0>
conn = <urllib3.connection.HTTPSConnection object at 0x7fb661a4c280>
method = 'GET'
url = '/v2/countries/IND/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
body = None
headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept': '*/*', 'Connection': 'keep-alive'}
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None)
timeout = Timeout(connect=30, read=30, total=None), chunked = False
response_conn = <urllib3.connection.HTTPSConnection object at 0x7fb661a4c280>
preload_content = False, decode_content = False, enforce_content_length = True
def _make_request(
self,
conn: BaseHTTPConnection,
method: str,
url: str,
body: _TYPE_BODY | None = None,
headers: typing.Mapping[str, str] | None = None,
retries: Retry | None = None,
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
chunked: bool = False,
response_conn: BaseHTTPConnection | None = None,
preload_content: bool = True,
decode_content: bool = True,
enforce_content_length: bool = True,
) -> BaseHTTPResponse:
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param url:
The URL to perform the request on.
:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param chunked:
If True, urllib3 will send the body using chunked transfer
encoding. Otherwise, urllib3 will send the body using the standard
content-length form. Defaults to False.
:param response_conn:
Set this to ``None`` if you will handle releasing the connection or
set the connection to have the response release it.
:param preload_content:
If True, the response's body will be preloaded during construction.
:param decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.
:param enforce_content_length:
Enforce content length checking. Body returned by server must match
value of Content-Length header, if present. Otherwise, raise error.
"""
self.num_requests += 1
timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
try:
# Trigger any extra validation we need to do.
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
# _validate_conn() starts the connection to an HTTPS proxy
# so we need to wrap errors with 'ProxyError' here too.
except (
OSError,
NewConnectionError,
TimeoutError,
BaseSSLError,
CertificateError,
SSLError,
) as e:
new_e: Exception = e
if isinstance(e, (BaseSSLError, CertificateError)):
new_e = SSLError(e)
# If the connection didn't successfully connect to it's proxy
# then there
if isinstance(
new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
) and (conn and conn.proxy and not conn.has_connected_to_proxy):
new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
raise new_e
# conn.request() calls http.client.*.request, not the method in
# urllib3.request. It also calls makefile (recv) on the socket.
try:
conn.request(
method,
url,
body=body,
headers=headers,
chunked=chunked,
preload_content=preload_content,
decode_content=decode_content,
enforce_content_length=enforce_content_length,
)
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
pass
except OSError as e:
# MacOS/Linux
# EPROTOTYPE and ECONNRESET are needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
raise
# Reset the timeout for the recv() on the socket
read_timeout = timeout_obj.read_timeout
if not conn.is_closed:
# In Python 3 socket.py will catch EAGAIN and return None when you
# try and read into the file pointer created by http.client, which
# instead raises a BadStatusLine exception. Instead of catching
# the exception and assuming all BadStatusLine exceptions are read
# timeouts, check for a zero timeout before making the request.
if read_timeout == 0:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={read_timeout})"
)
conn.timeout = read_timeout
# Receive the response from the server
try:
> response = conn.getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:534:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connection.py:516: in getresponse
httplib_response = super().getresponse()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:1377: in getresponse
response.begin()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:320: in begin
version, status, reason = self._read_status()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/http/client.py:281: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
../../../micromamba/envs/climada_env_3.9/lib/python3.9/socket.py:704: in readinto
return self._sock.recv_into(b)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1275: in recv_into
return self.read(nbytes, buffer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ssl.SSLSocket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
len = 8192, buffer = <memory at 0x7fb6820461c0>
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
if self._sslobj is None:
raise ValueError("Read on closed or unwrapped SSL socket.")
try:
if buffer is not None:
> return self._sslobj.read(len, buffer)
E socket.timeout: The read operation timed out
../../../micromamba/envs/climada_env_3.9/lib/python3.9/ssl.py:1133: timeout
The above exception was the direct cause of the following exception:
self = <requests.adapters.HTTPAdapter object at 0x7fb661a4c700>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
> resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:667:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:841: in urlopen
retries = retries.increment(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/retry.py:474: in increment
raise reraise(type(error), error, _stacktrace)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/util/util.py:39: in reraise
raise value
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:787: in urlopen
response = self._make_request(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:536: in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x7fb661a4cbe0>
err = timeout('The read operation timed out')
url = '/v2/countries/IND/indicators/NY.GDP.MKTP.CD?date=1960%3A2030&per_page=25000&format=json'
timeout_value = 30
def _raise_timeout(
self,
err: BaseSSLError | OSError | SocketTimeout,
url: str,
timeout_value: _TYPE_TIMEOUT | None,
) -> None:
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
if isinstance(err, SocketTimeout):
> raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={timeout_value})"
) from err
E urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/urllib3/connectionpool.py:367: ReadTimeoutError
During handling of the above exception, another exception occurred:
self = <climada.util.test.test_finance.TestWBWealthAccount testMethod=test_tow_IND_1985_pass>
def test_tow_IND_1985_pass(self):
"""Test Total Wealth value India 1985 (outside year range)."""
ref_year = 1985
cntry_iso = "IND"
var_name = "NW.TOW.TO"
> wb_year, wb_val, _ = world_bank_wealth_account(
cntry_iso, ref_year, variable_name=var_name
)
climada/util/test/test_finance.py:212:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/finance.py:431: in world_bank_wealth_account
gdp_year, gdp0_val = gdp(cntry_iso, np.min(years))
climada/util/finance.py:172: in gdp
close_year, close_val = world_bank(cntry_iso, ref_year, "NY.GDP.MKTP.CD")
climada/util/finance.py:209: in world_bank
cntry_gdp = wb.download(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:861: in download
return WorldBankReader(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:641: in read
return self._read()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/wb.py:650: in _read
df = self._read_one_data(self.url + indicator, self.params)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:110: in _read_one_data
out = self._get_response(url, params=params).json()
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/pandas_datareader/base.py:155: in _get_response
response = self.session.get(
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:602: in get
return self.request("GET", url, **kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:589: in request
resp = self.send(prep, **send_kwargs)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/sessions.py:703: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <requests.adapters.HTTPAdapter object at 0x7fb661a4c700>
request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=30, read=30, total=None), verify = True, cert = None
proxies = OrderedDict()
def send(
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
):
"""Sends PreparedRequest object. Returns Response object.
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
:param stream: (optional) Whether to stream the request content.
:param timeout: (optional) How long to wait for the server to send
data before giving up, as a float, or a :ref:`(connect timeout,
read timeout) <timeouts>` tuple.
:type timeout: float or tuple or urllib3 Timeout object
:param verify: (optional) Either a boolean, in which case it controls whether
we verify the server's TLS certificate, or a string, in which case it
must be a path to a CA bundle to use
:param cert: (optional) Any user-provided SSL certificate to be trusted.
:param proxies: (optional) The proxies dictionary to apply to the request.
:rtype: requests.Response
"""
try:
conn = self.get_connection_with_tls_context(
request, verify, proxies=proxies, cert=cert
)
except LocationValueError as e:
raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
self.add_headers(
request,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
)
chunked = not (request.body is None or "Content-Length" in request.headers)
if isinstance(timeout, tuple):
try:
connect, read = timeout
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError:
raise ValueError(
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
f"or a single float to set both timeouts to the same value."
)
elif isinstance(timeout, TimeoutSauce):
pass
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
resp = conn.urlopen(
method=request.method,
url=url,
body=request.body,
headers=request.headers,
redirect=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout,
chunked=chunked,
)
except (ProtocolError, OSError) as err:
raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
# TODO: Remove this in 3.0.0: see #2811
if not isinstance(e.reason, NewConnectionError):
raise ConnectTimeout(e, request=request)
if isinstance(e.reason, ResponseError):
raise RetryError(e, request=request)
if isinstance(e.reason, _ProxyError):
raise ProxyError(e, request=request)
if isinstance(e.reason, _SSLError):
# This branch is for urllib3 v1.22 and later.
raise SSLError(e, request=request)
raise ConnectionError(e, request=request)
except ClosedPoolError as e:
raise ConnectionError(e, request=request)
except _ProxyError as e:
raise ProxyError(e)
except (_SSLError, _HTTPError) as e:
if isinstance(e, _SSLError):
# This branch is for urllib3 versions earlier than v1.22
raise SSLError(e, request=request)
elif isinstance(e, ReadTimeoutError):
> raise ReadTimeout(e, request=request)
E requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.worldbank.org', port=443): Read timed out. (read timeout=30)
../../../micromamba/envs/climada_env_3.9/lib/python3.9/site-packages/requests/adapters.py:713: ReadTimeout