import asyncio
import aiohttp
from aiohttp_proxy import ProxyConnector
async def getResponse(url, proxy):
if proxy[0].isalpha() != True:
proxy = "http://" + proxy
async with aiohttp.ClientSession(connector=ProxyConnector.from_url(proxy)) as session:
async with session.get(url) as response:
if response.status == 200:
return await response.text()
async def main():
print(await getResponse("https://ifconfig.me/ip", "207.154.237.71:3128"))
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Traceback (most recent call last):
File "C:\Users\terno\Desktop\async\main.py", line 48, in <module>
loop.run_until_complete(main())
File "C:\Users\terno\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 468, in run_until_complete
return future.result()
File "C:\Users\terno\Desktop\async\main.py", line 33, in main
print(await getResponse("https://ifconfig.me/ip", "207.154.237.71:3128"))
File "C:\Users\terno\Desktop\async\main.py", line 27, in getResponse
async with session.get(url) as response:
File "C:\Users\terno\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\client.py", line 779, in __aenter__
self._resp = await self._coro
File "C:\Users\terno\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\client.py", line 319, in _request
traces=traces
TypeError: connect() missing 1 required positional argument: 'timeout'
Обычно сообщения такого формата бывают если сделать так;
И выведет что то такое:
<function foo at 0x0000023A25AF0D90>