-
import asyncio, httpx
async def req(url):
request = httpx.Request("GET", url)
resp = await client.send(request)
request = httpx.Request("GET", url, cookies=resp.cookies)
resp = await client.send(request)
client = httpx.AsyncClient()
urls = [...]
asyncio.run(asyncio.gather(*[req(url) for url in urls])) Are we allowed to use single main instance and use it with different request options? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @byehack — yes that is recommended but you'll want to context manage the client async def main:
async with httpx.AsyncClient() as client:
.... See https://www.python-httpx.org/async/#making-async-requests |
Beta Was this translation helpful? Give feedback.
-
Thanks @madkinsz |
Beta Was this translation helpful? Give feedback.
Hey @byehack — yes that is recommended but you'll want to context manage the client
See https://www.python-httpx.org/async/#making-async-requests