Answer the question
In order to leave comments, you need to log in
Why can't I get responses from tasks (asyncio) when working with httpx?
Hello! I worked before with the aiohttp library, but due to the fact that this library does not support HTTPS protocol, I decided to try httpx. There was a problem with the fact that I can not get answers from tasks, I can not understand what the problem is. What exactly am I doing wrong?
from typing import AsyncIterable
import httpx
import asyncio
proxies = [] # Здесь у меня список проксей.
async def a():
tasks = []
for proxy in proxies:
tasks.append(loop.create_task(b(proxy)))
result = await asyncio.gather(*tasks)
print(result)
async def b(proxy):
async with httpx.AsyncClient(proxies=proxy) as client:
response = await client.get('https://wtfismyip.com/text')
return response.text
loop = asyncio.get_event_loop()
loop.create_task(a())
loop.run_forever()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question