From 275bc49ffda1b75ec6e6d9115354df07b86b3233 Mon Sep 17 00:00:00 2001 From: matze Date: Thu, 7 Nov 2024 17:47:18 +0100 Subject: [PATCH] multiple retries for fetching token --- neofarm/lib.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/neofarm/lib.py b/neofarm/lib.py index b1e4b31..64a787b 100644 --- a/neofarm/lib.py +++ b/neofarm/lib.py @@ -10,15 +10,22 @@ api_root = root_url + 'api/' token_url = root_url + 'oauth/token/' client_id = 'neofarm' client_secret = 'Wk&%g#d8lYFUDrU7k7k%5ZS$V@hHauBq' +fetch_retries = 10; def init_api(): client = BackendApplicationClient(client_id=client_id) oauth_session = OAuth2Session(client=client) - token = oauth_session.fetch_token( - token_url = token_url, - client_id = client_id, - client_secret = client_secret - ) + for i in range(fetch_retries): + try: + token = oauth_session.fetch_token( + token_url = token_url, + client_id = client_id, + client_secret = client_secret + ) + break + except ConnectionError: + print("Fehler bei Verbindung mit Server (wahrscheinlich DuckDns) probiere erneut...") + oauth = OAuth2(client_id=client_id, client=client, token=token) api = jsonapi_requests.orm.OrmApi.config({