Logging instructions in README not working
jwodder opened this issue · 1 comments
jwodder commented
My attempts to get logging of retries working following the instructions in this project's README are proving fruitless. Using aiohttp 3.8.3 and aiohttp-retry 2.8.3 on Python 3.10.9 on macOS 11.7.2, the following code never prints the "Making a request" line. Please advise.
import asyncio
import aiohttp
from aiohttp_retry import RetryClient, ListRetry
async def on_request_start(session, trace_config_ctx, params):
print("Making a request ...")
async def get_client():
trace_config = aiohttp.TraceConfig()
trace_config.on_request_start.append(on_request_start)
return RetryClient(
client_session=aiohttp.ClientSession(),
retry_options=ListRetry(timeouts=[1, 2, 6, 15, 36]),
trace_configs=[trace_config],
)
async def amain():
async with (await get_client()) as session:
async with session.get("https://httpbin.org/status/500") as r:
print(r.status)
if __name__ == "__main__":
asyncio.run(amain())
jwodder commented
I realized what I was doing wrong. Because I'm passing an explicit ClientSession
to RetryClient
, I need to pass trace_configs
to the ClientSession
instead.