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? |
Answered by
zanieb
Jan 31, 2023
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 |
0 replies
Answer selected by
zanieb
|
Thanks @madkinsz |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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