From 591f933db0a7e2ae1556d02091317273df8a41f9 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:52:00 +0200 Subject: [PATCH] usage of retry-after header information in bf api call --- cbpi/__init__.py | 2 +- cbpi/controller/upload_controller.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 9c72a9f..347c28e 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.2" +__version__ = "4.4.3.a1" __codename__ = "Yeast Starter" diff --git a/cbpi/controller/upload_controller.py b/cbpi/controller/upload_controller.py index a4d86fd..1663730 100644 --- a/cbpi/controller/upload_controller.py +++ b/cbpi/controller/upload_controller.py @@ -92,9 +92,19 @@ class UploadController: async with aiohttp.ClientSession(headers=headers) as bf_session: async with bf_session.get(self.url, params=parameters) as r: if r.status == 429: - logging.error("Too many requests to BF api. Try again later") - self.cbpi.notify("Error", "Too many requests to BF api. Try again later", NotificationType.ERROR) + try: + seconds=int(r.headers['Retry-After']) + minutes=round(seconds/60) + except: + seconds=None + if not seconds: + logging.error("Too many requests to BF api. Try again later") + self.cbpi.notify("Error", "Too many requests to BF api. Try again later", NotificationType.ERROR) + else: + logging.error(f"Too many requests to BF api. Try in {minutes} minutes again.") + self.cbpi.notify("Error", f"Too many requests to BF api. Try in {minutes} minutes again.", NotificationType.ERROR) repeat = False + logging.error(r.headers['Retry-After']) else: bf_recipe_list = await r.json() await bf_session.close()