From a3f8cb31ef9362efbaee4f1474d08ad569f06ead Mon Sep 17 00:00:00 2001 From: Danamir Date: Thu, 2 May 2024 08:14:48 +0200 Subject: [PATCH] Also try the old API key authentication method if the PAT one is rejected --- livedns_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/livedns_client.py b/livedns_client.py index 01e5492..cc52602 100644 --- a/livedns_client.py +++ b/livedns_client.py @@ -51,6 +51,12 @@ def _query_api(self, method, query, json_data=None): # request try: r = requests.request(method=method, url=url, headers=headers, json=json_data, timeout=60.0) + if r.status_code == 403: + # on reject, also try the old API key authentication method + headers["Authorization"] = headers.get("Authorization").replace("Bearer", "Apikey") + if self.debug: + print("Requests: method=%s url=%s headers=%s json=%s" % (method, url, headers, json_data)) + r = requests.request(method=method, url=url, headers=headers, json=json_data, timeout=60.0) except Timeout: if self.debug: print("Timeout error.")