如何记录 httpx 请求的所有请求标头?我使用日志级别 DEBUG nad 响应标头日志正常,但日志中没有请求标头。如果重要的话,我正在使用 httpx lib 的异步 api。
使用自定义事件挂钩:
import httpx
import logging
logging.basicConfig(level=logging.DEBUG)
async def log_request(request):
logging.debug(f"Request headers: {request.headers}")
async with httpx.AsyncClient(event_hooks={'request': [log_request]}) as client:
response = await client.get('https://httpbin.org/get')