我正在尝试打印出我正在发送的请求的方法和标头。我可以为请求的响应而这样做,但不能为实际请求本身这样做。
以下是问题所在:
async with session.get('url', params=params) as resp:
print(resp.method)
content = await
resp.read()
您想要的是request_info
吗?有关更多详细信息,请参阅文档。
async with session.get('https://www.python.org/', params=params) as resp:
print(resp.request_info)
content = await resp.read()
> RequestInfo(url=URL('https://www.python.org/'), method='GET', headers=<CIMultiDictProxy('Host': 'www.python.org', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.9 aiohttp/3.8.1')>, real_url=URL('https://www.python.org/'))