ckuhtz / ham

ham radio experiments
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

make pskreporter query robustly retryable #10

Open ckuhtz opened 5 months ago

ckuhtz commented 5 months ago

https://github.com/ckuhtz/ham/blob/b714bb0db1b39ddc63c5573de270b430b69c85ff/pskreporter/pskreporter2pubsub.py#L69-L74

ckuhtz commented 5 months ago

for example, temporary name resolution errors, keep trying until succeeded or some other configurable event takes place. currently, a fixed number of retries occur and the code bails with connection error when resolution continues to fail.

waiting for 5 minutes..
Received '{"type": "minute"}' for 0 out of 5 times.
Received '{"type": "minute"}' for 1 out of 5 times.
Received '{"type": "minute"}' for 2 out of 5 times.
Received '{"type": "minute"}' for 3 out of 5 times.
Received '{"type": "minute"}' for 4 out of 5 times.
Received '{"type": "minute"}' for 5 out of 5 times.
wait is over.
getting PSKreporter data: https://retrieve.pskreporter.info/query?senderCallsign=AK7VV
Traceback (most recent call last):
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connection.py", line 198, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/python/3.12.2/lib/python3.12/socket.py", line 963, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -3] Temporary failure in name resolution

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

Traceback (most recent call last):
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1099, in _validate_conn
    conn.connect()
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connection.py", line 616, in connect
    self.sock = sock = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connection.py", line 205, in _new_conn
    raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x7598f893e7e0>: Failed to resolve 'retrieve.pskreporter.info' ([Errno -3] Temporary failure in name resolution)

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

Traceback (most recent call last):
  File "/home/christian/.local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='retrieve.pskreporter.info', port=443): Max retries exceeded with url: /query?senderCallsign=AK7VV (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7598f893e7e0>: Failed to resolve 'retrieve.pskreporter.info' ([Errno -3] Temporary failure in name resolution)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/src/github.com/ckuhtz/ham/pskreporter/pskreporter2pubsub.py", line 71, in <module>
    response = requests.get(pskreporter_url)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='retrieve.pskreporter.info', port=443): Max retries exceeded with url: /query?senderCallsign=AK7VV (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7598f893e7e0>: Failed to resolve 'retrieve.pskreporter.info' ([Errno -3] Temporary failure in name resolution)"))