tomasbedrich / pycaching

A Python 3 interface for working with Geocaching.com website.
https://pycaching.readthedocs.io/
GNU Lesser General Public License v3.0
61 stars 46 forks source link

`Remote end closed connection without response` when using `Geocaching.search()` #182

Closed BelKed closed 1 year ago

BelKed commented 2 years ago

When trying to load caches in some location using Geocaching.search(), it doesn't work because of error (Remote end closed connection without response). However, loading a single geocache using Geocaching.get_cache() seems to work fine...



Python code with error:

import pycaching

geocaching = pycaching.login("Username", "Password")

point = geocaching.geocode("Prague")

for cache in geocaching.search(point, limit=10):
    print(cache.name)

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.10/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pycaching/geocaching.py", line 82, in _request
    res = self._session.request(method, url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 723, in send
    history = [resp for resp in gen]
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 723, in <listcomp>
    history = [resp for resp in gen]
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 266, in resolve_redirects
    resp = self.send(
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Documents/test.py", line 7, in <module>
    for cache in geocaching.search(point, limit=10):
  File "/usr/local/lib/python3.10/site-packages/pycaching/geocaching.py", line 257, in search
    geocaches_table, whole_page = self._search_get_page(point, start_index)
  File "/usr/local/lib/python3.10/site-packages/pycaching/geocaching.py", line 327, in _search_get_page
    res = self._request(
  File "/usr/local/lib/python3.10/site-packages/pycaching/geocaching.py", line 94, in _request
    if e.response.status_code == 429:  # Handle rate limiting errors
AttributeError: 'NoneType' object has no attribute 'status_code'

Edit: Updated the traceback.

FriedrichFroebel commented 2 years ago

Thanks for your report. When reviewing the latest pull request, I stumbled upon some issue when updating the test cases which seems to be related to this. At the moment some tests for the search functionality are either out-of-date or marked as expected failures.

I did not have yet have enough time for looking into this. Feel free to have a deeper look at this to get it back working as expected.

OliverBurgert commented 2 years ago

I have exactly the same issue when I try the example from the docs:

point = Point(56.25263, 15.26738)

for cache in geocaching.search(point, limit=50):
    if cache.type == Type.traditional:
        print(cache.name)

Changing the limit (even to 1) does not make any difference.

FriedrichFroebel commented 2 years ago

I am not sure if we are able to do anything about this as already mentioned in my last comment. We might be able to catch this in https://github.com/tomasbedrich/pycaching/blob/master/pycaching/geocaching.py#L94 and report "Cannot load page" instead, but this would not be really helpful either. If you want to dig into this to find a solution, feel free to do so.

This might be fixed by #175 as well, but this is still work in progress without recent changes.

TrollBlox commented 2 years ago

I get the same issue except the error message is Remote end closed connection without response

rainermensing commented 1 year ago

I get the same issue except the error message is Remote end closed connection without response @TrollBlox Same here on version 4.2.3 with Python 3.10.7 on Windows 10

Traceback (most recent call last):
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Python310\lib\http\client.py", line 1374, in getresponse
    response.begin()
  File "C:\Python310\lib\http\client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "C:\Python310\lib\http\client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\util\retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Python310\lib\http\client.py", line 1374, in getresponse
    response.begin()
  File "C:\Python310\lib\http\client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "C:\Python310\lib\http\client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\pycaching\geocaching.py", line 82, in _request
    res = self._session.request(method, url, **kwargs)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\sessions.py", line 723, in send
    history = [resp for resp in gen]
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\sessions.py", line 723, in <listcomp>
    history = [resp for resp in gen]
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\sessions.py", line 266, in resolve_redirects
    resp = self.send(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\requests\adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\adhoc.py", line 25, in <module>
    for cache in geocaching.search(point, limit=1):
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\pycaching\geocaching.py", line 257, in search
    geocaches_table, whole_page = self._search_get_page(point, start_index)
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\pycaching\geocaching.py", line 326, in _search_get_page
    res = self._request(
  File "C:\Users\raine\Documents\GitHub\geo-app\backend\venv\lib\site-packages\pycaching\geocaching.py", line 94, in _request
    if e.response.status_code == 429:  # Handle rate limiting errors
AttributeError: 'NoneType' object has no attribute 'status_code'
BelKed commented 1 year ago

I somehow forgot to mention this issue in https://github.com/tomasbedrich/pycaching/pull/206, where it was also fixed...