Using asyncio
and aiohttp
, I have implemented an async function that triggers an API get request. I am trying to add a retry mechanism to this function to asynchronously retry failed API requests 5 times. This is what I have done using the backoff
decorator:
@backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, max_tries=5)
async def call_url(language: str, word:str, headers:dict) -> bytes:
url = f"https://od-api.oxforddictionaries.com:443/api/v2/entries/{language}/{word.lower()}"
print(f"Started: {url}")
try:
async with aiohttp.ClientSession(headers=headers) as session:
async with session.get(url, raise_for_status=True) as response:
content = await response.read()
status = response.status
print("Finished: ", status)
return status
except aiohttp.ClientResponseError as e:
print("Finished: ", e.status)
return e.status
This is implemented in Jupyter Notebook, and I would like to see the backoff retry logs either in the stdout or in a file. Is there anyway to see the logs while backoff is retrying failed API requests? In the backoff documentation, it says:
By default, backoff and retry attempts are logged to the ‘backoff’ logger. By default, this logger is configured with a NullHandler, so there will be nothing output unless you configure a handler.
How do I access the contents of the backoff logger?