Skip to content

Instantly share code, notes, and snippets.

@zealws
Last active September 30, 2020 20:25
Show Gist options
  • Save zealws/3be80baf32ff5a1131b9e7982ba34659 to your computer and use it in GitHub Desktop.
Save zealws/3be80baf32ff5a1131b9e7982ba34659 to your computer and use it in GitHub Desktop.
Demonstration of Unix socket connector error before/after change to aiohttp
(venv) zeal@zealx1 ~ $ python client.py
Traceback (most recent call last):
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 1113, in _create_connection
_, proto = await self._loop.create_unix_connection(
File "/usr/lib/python3.8/asyncio/unix_events.py", line 244, in create_unix_connection
await self.sock_connect(sock, path)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
return await fut
File "/usr/lib/python3.8/asyncio/selector_events.py", line 499, in _sock_connect
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "client.py", line 15, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "client.py", line 9, in main
r = await session.get('http://host/')
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/client.py", line 446, in _request
conn = await self._connector.connect(
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 507, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 1116, in _create_connection
raise UnixClientConnectorError(self.path, req.connection_key, exc) from exc
aiohttp.client_exceptions.UnixClientConnectorError: Cannot connect to unix socket /tmp/server.sock ssl:default [Connection refused]
(venv) zeal@zealx1 ~ $ python client.py
Traceback (most recent call last):
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 1112, in _create_connection
_, proto = await self._loop.create_unix_connection(
File "/usr/lib/python3.8/asyncio/unix_events.py", line 244, in create_unix_connection
await self.sock_connect(sock, path)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
return await fut
File "/usr/lib/python3.8/asyncio/selector_events.py", line 499, in _sock_connect
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "client.py", line 15, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "client.py", line 9, in main
r = await session.get('http://host/')
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/client.py", line 446, in _request
conn = await self._connector.connect(
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 506, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/zeal/dev/aiohttp/venv/lib/python3.8/site-packages/aiohttp-4.0.0a1-py3.8-linux-x86_64.egg/aiohttp/connector.py", line 1115, in _create_connection
raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host host:80 ssl:default [Connection refused]
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession(
connector=aiohttp.UnixConnector(path='/tmp/server.sock'),
) as session:
r = await session.get('http://host/')
print("Status:", r.status)
print("Text:")
print((await r.text()).strip())
asyncio.get_event_loop().run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment