We can easily create a persistent session using:
s = requests.Session()
But how to achieve this using httpx library?
async with httpx.AsyncClient() as client:
response = await client.get(
URL,
params=params,
)
Just dont use the context manager.
client = httpx.AsyncClient()
response = await client.get(
URL,
params=params,
)
Or if you want to have the same cleanup functionality:
client = httpx.AsyncClient()
try:
response = await client.get(
URL,
params=params,
)
# do other stuff
finally:
await client.aclose()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With