Hello, I'm calling an API every minute using an AlwaysOnTask. The code worked for months, but since this morning around 5AM it stopped working (and I didn't change anything in my code). This is the trace:
2024-03-21 12:54:38 - Task preparing to start
Mar 21 12:55:06 Traceback (most recent call last):
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
Mar 21 12:55:06 conn = connection.create_connection(
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection
Mar 21 12:55:06 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
Mar 21 12:55:06 File "/usr/local/lib/python3.9/socket.py", line 953, in getaddrinfo
Mar 21 12:55:06 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
Mar 21 12:55:06 socket.gaierror: [Errno -3] Temporary failure in name resolution
Mar 21 12:55:06 During handling of the above exception, another exception occurred:
Mar 21 12:55:06 Traceback (most recent call last):
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
Mar 21 12:55:06 httplib_response = self._make_request(
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request
Mar 21 12:55:06 self._validate_conn(conn)
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
Mar 21 12:55:06 conn.connect()
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 353, in connect
Mar 21 12:55:06 conn = self._new_conn()
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
Mar 21 12:55:06 raise NewConnectionError(
Mar 21 12:55:06 urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7ff9e05fbca0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution
Mar 21 12:55:06 During handling of the above exception, another exception occurred:
Mar 21 12:55:06 Traceback (most recent call last):
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
Mar 21 12:55:06 resp = conn.urlopen(
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
Mar 21 12:55:06 retries = retries.increment(
Mar 21 12:55:06 File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 573, in increment
Mar 21 12:55:06 raise MaxRetryError(_pool, url, error or ResponseError(cause))
Mar 21 12:55:06 urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='data.trafficintelligence.ch', port=443): Max retries exceeded with url: /v1/Token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff9e05fbca0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
Mar 21 12:55:06 During handling of the above exception, another exception occurred:
Mar 21 12:55:06 Traceback (most recent call last):
Mar 21 12:55:06 File "/home/mattia90/mysite/update_traffic.py", line 33, in <module>
Mar 21 12:55:06 api = api_manager.Api_Manager()
Mar 21 12:55:06 File "/home/mattia90/mysite/api_manager.py", line 12, in __init__
Mar 21 12:55:06 self.generateToken()
Mar 21 12:55:06 File "/home/mattia90/mysite/api_manager.py", line 16, in generateToken
Mar 21 12:55:06 response = requests.post(self._API_TOKEN_URL, data=data)
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/api.py", line 115, in post
Mar 21 12:55:06 return request("post", url, data=data, json=json, **kwargs)
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/api.py", line 59, in request
Mar 21 12:55:06 return session.request(method=method, url=url, **kwargs)
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
Mar 21 12:55:06 resp = self.send(prep, **send_kwargs)
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
Mar 21 12:55:06 r = adapter.send(request, **kwargs)
Mar 21 12:55:06 File "/home/mattia90/.local/lib/python3.9/site-packages/requests/adapters.py", line 519, in send
Mar 21 12:55:06 raise ConnectionError(e, request=request)
Mar 21 12:55:06 requests.exceptions.ConnectionError: HTTPSConnectionPool(host='data.trafficintelligence.ch', port=443): Max retries exceeded with url: /v1/Token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff9e05fbca0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
If I call the API using the console, everything works as expected. It is failing only with the AlwaysOnTask apparently.
def generateToken(self):
data = { "username": self._USER, "password": self._PASSWORD, "grant_type": "password" }
response = requests.post(self._API_TOKEN_URL, data=data)
if response.status_code == 200:
self._last_token = json.loads(response.content)['access_token']