usage of retry-after header information in bf api call

This commit is contained in:
avollkopf 2024-07-01 22:52:00 +02:00
parent c26891180d
commit 591f933db0
2 changed files with 13 additions and 3 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.2"
__version__ = "4.4.3.a1"
__codename__ = "Yeast Starter"

View file

@ -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()