Connection Reset by peer error using aiohttp and asyncio

Hi Team,
I am getting aiohttp.client_exceptions.ClientConnectorError upon using aiohttp and asyncio together. I am gathering all tasks using one session by aiohttp and getting responses.

Can someone please help here ?

---------------------------------------------- SCRIPT RUN TRACEBACK -------------------------------------------------

Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File “/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py”, line 1081, in create_connection
transport, protocol = await self._create_connection_transport(
File “/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py”, line 1111, in _create_connection_transport
await waiter
File “/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py”, line 856, in _read_ready__data_received
data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 54] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/async_test2.py”, line 59, in
asyncio.run(push_ips())
File “/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py”, line 44, in run
return loop.run_until_complete(main)
File “/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py”, line 642, in run_until_complete
return future.result()
File “/async_test2.py”, line 54, in push_ips
responses = await asyncio.gather(*tasks)
File “/usr/local/lib/python3.9/site-packages/aiohttp/client.py”, line 1104, in throw
self._coro.throw(arg)
File “/usr/local/lib/python3.9/site-packages/aiohttp/client.py”, line 520, in _request
conn = await self._connector.connect(
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 1051, in _create_direct_connection
raise last_exc
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File “/usr/local/lib/python3.9/site-packages/aiohttp/connector.py”, line 975, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host xxxxxxxxxxxxxx ssl:False [Connection reset by peer]

---------------------------------------------------- SCRIPT ----------------------------------------------------------

def get_tasks(session):
tasks = []
for item in ips:
tasks.append(session.get(base_url, ssl=False))
return tasks

async def push_ips():
async with aiohttp.ClientSession() as session:
tasks = get_tasks(session)
responses = await asyncio.gather(*tasks)
for response in responses:
print(response)

asyncio.run(push_ips())