metaodi / osmapi

Python wrapper for the OpenStreetMap API
http://osmapi.metaodi.ch/
GNU General Public License v3.0
211 stars 41 forks source link

occasional freezing on fetching data #170

Closed matkoniecz closed 1 month ago

matkoniecz commented 1 month ago

sometimes response from OSM API never arrives and osmapi hangs

at least for me raising exception on timeout would be preferable over entire program hanging forever

when I force-stopped it after minutes of waiting it gave me following stacktrace:

  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 361, in NodeGet
    data = self._get(uri)
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 2049, in _get
    return self._http('GET', path, False, None)
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 2007, in _http
    return self._http_request(
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 1976, in _http_request
    response = self._session.request(method, path, auth=user_pass,
  File "/home/mateusz/.local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/mateusz/.local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/mateusz/.local/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/mateusz/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/home/mateusz/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
  File "/home/mateusz/.local/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
  File "/usr/lib/python3.10/http/client.py", line 1375, in getresponse
    response.begin()
  File "/usr/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.10/ssl.py", line 1307, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.10/ssl.py", line 1163, in read
    return self._sslobj.read(len, buffer)
metaodi commented 1 month ago

It seems there is a timeout parameter for requests, so maybe this should be available as a parameter with a sensible default.

I think if you pass your own requests session object to Osmapi you could already define a timeout, but that"s not really obvious.