Open freyn-cna opened 2 years ago
Are you still having this problem? I'm also experiencing it.
Also having a similar one that raises ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
:
Python 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:37) [Clang 15.0.7 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import cenpy
---------------------------------------------------------------------------
RemoteDisconnected Traceback (most recent call last)
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connectionpool.py:790, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
789 # Make the request on the HTTPConnection object
--> 790 response = self._make_request(
791 conn,
792 method,
793 url,
794 timeout=timeout_obj,
795 body=body,
796 headers=headers,
797 chunked=chunked,
798 retries=retries,
799 response_conn=response_conn,
800 preload_content=preload_content,
801 decode_content=decode_content,
802 **response_kw,
803 )
805 # Everything went great!
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connectionpool.py:536, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
535 try:
--> 536 response = conn.getresponse()
537 except (BaseSSLError, OSError) as e:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connection.py:461, in HTTPConnection.getresponse(self)
460 # Get the response from http.client.HTTPConnection
--> 461 httplib_response = super().getresponse()
463 try:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:1378, in HTTPConnection.getresponse(self)
1377 try:
-> 1378 response.begin()
1379 except ConnectionError:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:318, in HTTPResponse.begin(self)
317 while True:
--> 318 version, status, reason = self._read_status()
319 if status != CONTINUE:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:287, in HTTPResponse._read_status(self)
284 if not line:
285 # Presumably, the server closed the connection before
286 # sending a valid response.
--> 287 raise RemoteDisconnected("Remote end closed connection without"
288 " response")
289 try:
RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
ProtocolError Traceback (most recent call last)
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
485 try:
--> 486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
489 body=request.body,
490 headers=request.headers,
491 redirect=False,
492 assert_same_host=False,
493 preload_content=False,
494 decode_content=False,
495 retries=self.max_retries,
496 timeout=timeout,
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connectionpool.py:844, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
842 new_e = ProtocolError("Connection aborted.", new_e)
--> 844 retries = retries.increment(
845 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
846 )
847 retries.sleep()
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/util/retry.py:470, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
469 if read is False or method is None or not self._is_method_retryable(method):
--> 470 raise reraise(type(error), error, _stacktrace)
471 elif read is not None:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/util/util.py:38, in reraise(tp, value, tb)
37 if value.__traceback__ is not tb:
---> 38 raise value.with_traceback(tb)
39 raise value
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connectionpool.py:790, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
789 # Make the request on the HTTPConnection object
--> 790 response = self._make_request(
791 conn,
792 method,
793 url,
794 timeout=timeout_obj,
795 body=body,
796 headers=headers,
797 chunked=chunked,
798 retries=retries,
799 response_conn=response_conn,
800 preload_content=preload_content,
801 decode_content=decode_content,
802 **response_kw,
803 )
805 # Everything went great!
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connectionpool.py:536, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
535 try:
--> 536 response = conn.getresponse()
537 except (BaseSSLError, OSError) as e:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/urllib3/connection.py:461, in HTTPConnection.getresponse(self)
460 # Get the response from http.client.HTTPConnection
--> 461 httplib_response = super().getresponse()
463 try:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:1378, in HTTPConnection.getresponse(self)
1377 try:
-> 1378 response.begin()
1379 except ConnectionError:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:318, in HTTPResponse.begin(self)
317 while True:
--> 318 version, status, reason = self._read_status()
319 if status != CONTINUE:
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/http/client.py:287, in HTTPResponse._read_status(self)
284 if not line:
285 # Presumably, the server closed the connection before
286 # sending a valid response.
--> 287 raise RemoteDisconnected("Remote end closed connection without"
288 " response")
289 try:
ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import cenpy
File ~/cenpy/cenpy/__init__.py:4
1 __version__ = "1.0.1"
2 __author__ = "Levi John Wolf levi.john.wolf@gmail.com"
----> 4 from . import explorer
5 from .remote import APIConnection as _APIConnection
6 from .tools import _load_sitekey, set_sitekey
File ~/cenpy/cenpy/explorer.py:13
9 unicode = str
11 fp = os.path.dirname(os.path.realpath(__file__))
---> 13 resp = raw_APIs = r.get("https://api.census.gov/data.json")
14 try:
15 resp.raise_for_status()
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/api.py:73, in get(url, params, **kwargs)
62 def get(url, params=None, **kwargs):
63 r"""Sends a GET request.
64
65 :param url: URL for the new :class:`Request` object.
(...)
70 :rtype: requests.Response
71 """
---> 73 return request("get", url, params=params, **kwargs)
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs)
55 # By using the 'with' statement we are sure the session is closed, thus we
56 # avoid leaving sockets open which can trigger a ResourceWarning in some
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
584 send_kwargs = {
585 "timeout": timeout,
586 "allow_redirects": allow_redirects,
587 }
588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
591 return resp
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
700 start = preferred_clock()
702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
705 # Total elapsed time of the request (approximately)
706 elapsed = preferred_clock() - start
File ~/mambaforge/envs/py311_cenpy/lib/python3.11/site-packages/requests/adapters.py:501, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
(...)
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
--> 501 raise ConnectionError(err, request=request)
503 except MaxRetryError as e:
504 if isinstance(e.reason, ConnectTimeoutError):
505 # TODO: Remove this in 3.0.0: see #2811
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Hmm. So, these are failures to download the data.json
that structures the automatically-generated portion of the API. That download has grown since the package was written from something below 1MB to about 4MB today.
We could make this asynchronous and cached, which would avoid this at import, but eventually that needs to get downloaded to generate the metadata about the census data products.
I will try to work through this in the coming weeks.
Also, FWIW:
ConnectionError
on my personal and work macOS (work goes through VPN)cenpy
without problem on multiple work VMs (Linux)
I'm not 100% sure how environment-specific this might be, but I am getting my connections remotely closed on package import (10054). This first started happening on code that had previously worked in Jupyter on Windows last week, but I've also tried it in the terminal, and tried creating a new conda environment with fresh installs of everything and it keeps happening in both Jupyter and terminal. Is this happening to anyone else? I should note that I have a version of this script in a Databricks environment where I don't seem to be having this problem, but 1) I have to pip-install on Databricks using subprocess and I don't want to do that on my local machine; 2) the script is too resource-intensive to develop entirely on Databricks.
If others can confirm they do not have this issue, let me know and I will close it.
Terminal output follows below: