Reputation: 173
I'm using aiohttp and want to log the raw request in ClientSession before it's sent. I saw that for requests module, it is doable: Python requests - print entire http request (raw)?
But when I tried finding for aiohttp, I can only find for request headers, but what I want is the body: Dumping the request headers with aiohttp
I have looked into the source code for tracing but all I can find is the ClientResponse class being used and no instances of ClientRequest class being used: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/tracing.py
Upvotes: 10
Views: 1637
Reputation: 151
You can inspect the request body using tracing as the following:
async def on_request_chunk_sent(session, trace_config_ctx, chunk):
print("Chunk sent request", chunk)
trace_config = aiohttp.TraceConfig()
trace_config.on_request_chunk_sent.append(on_request_chunk_sent)
async with aiohttp.ClientSession(trace_configs=[trace_config]) as session:
...
For more info, refer to the docs.
Upvotes: 1