Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unix-Sockets connection not working

See original GitHub issue

Using podman-py we cannot connect to a local unix-socket. Irrespective of how we communicate the protocol, it will always end up as http.

The following does not work, it will end up making an http-request to http://%2frun%2fpodman.sock/v4.0.0/libpod/version instead of the unix-socket.

def podman_py():
    from podman import PodmanClient

    uri = "unix:///run/podman.sock"

    with PodmanClient(base_url=uri) as client:
        version = client.version()  # fails
        print("Release: ", version["Version"])
        print("Compatible API: ", version["ApiVersion"])
        print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")

For comparison, the following, manual connection to the socket works:

def podman_requests_unixsocket():
    import requests_unixsocket

    url = "http+unix://%2frun%2fpodman.sock/v4.0.0/libpod/version"

    with requests_unixsocket.Session() as session:
        response = session.get(url)
        version = json.loads(response.text)
        print("Release: ", version["Version"])
        print("Compatible API: ", version["ApiVersion"])
        print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")

My suspicion is that we are doing something wrong, or that something is lost in translation when hard-coding the protocol to http and then mapping to UDSAdapter down the line.

We made some manual changes to podman-py that seem to do the trick (although they look wrong to me):


    # Map supported schemes to Pool Classes
    _pool_classes_by_scheme = {
        "http": UDSConnectionPool,
        "http+unix": UDSConnectionPool,
        "http+ssh": UDSConnectionPool,

    # Map supported schemes to Pool Key index generator
    _key_fn_by_scheme = {
        "http": functools.partial(_key_normalizer, _PoolKey),
        "http+unix": functools.partial(_key_normalizer, _PoolKey),
        "http+ssh": functools.partial(_key_normalizer, _PoolKey),


        if self.base_url.scheme == "http+unix":
            self.mount("http+unix://", UDSAdapter(self.base_url.geturl(), **adapter_kwargs))


        uri = urllib.parse.ParseResult(
            urllib.parse.urljoin(path_prefix, path),

We are using version 4.0.0

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

rhatdancommented, Sep 6, 2022

@cdoern PTAL

cdoerncommented, Sep 9, 2022

@awildturtok can you please paste the output you get when this fails? also, please run systemctl start podman to ensure the socket it listening and that the system service is using this socket.

This most likely is not on our end, as I just fresh installed podman-py 4.2 and ran the test code, and it succeeded. I would assume the custom mounting of the socket is not right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unix socket connection not working · Issue #525 - GitHub
I managed to make it work by connecting to a public IP. Sockets did not work, now trying to use SSL, but when...
Read more >
Unix domain socket client won't connect - Stack Overflow
The server code seems to be working fine, however when I try to connect the client, the call to connect() fails. Here is...
Read more >
How to find other end of unix socket connection? - Server Fault
Here is an example showing an ssh-agent unix domain socket to which a ssh process has connected: $ sudo ss -a --unix -p...
Read more >
UNIX domain sockets - IBM
UNIX domain sockets enable efficient communication between processes that are running on the same z/TPF processor. UNIX domain sockets support both stream- ...
Read more >
B.3.2.2 Can't connect to [local] MySQL server
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found