multiple retries for fetching token

This commit is contained in:
2024-11-07 17:47:18 +01:00
parent 0b2ea9650c
commit 275bc49ffd

View File

@@ -10,15 +10,22 @@ api_root = root_url + 'api/'
token_url = root_url + 'oauth/token/' token_url = root_url + 'oauth/token/'
client_id = 'neofarm' client_id = 'neofarm'
client_secret = 'Wk&%g#d8lYFUDrU7k7k%5ZS$V@hHauBq' client_secret = 'Wk&%g#d8lYFUDrU7k7k%5ZS$V@hHauBq'
fetch_retries = 10;
def init_api(): def init_api():
client = BackendApplicationClient(client_id=client_id) client = BackendApplicationClient(client_id=client_id)
oauth_session = OAuth2Session(client=client) oauth_session = OAuth2Session(client=client)
token = oauth_session.fetch_token( for i in range(fetch_retries):
token_url = token_url, try:
client_id = client_id, token = oauth_session.fetch_token(
client_secret = client_secret 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) oauth = OAuth2(client_id=client_id, client=client, token=token)
api = jsonapi_requests.orm.OrmApi.config({ api = jsonapi_requests.orm.OrmApi.config({