Skip to content
MtrXTools

ConnectionRefusedError: [Errno 111] Connection refused

Nothing is listening on that port

Seen in Python socket, requests, urllib3, asyncio (Errno 61 on macOS)

The host answered but actively refused the TCP connection, because no process is listening on that address and port.

Common causes

  • The service is not running, or listens on a different port.
  • The service listens only on 127.0.0.1, but you connect from another host or container.
  • Inside Docker, "localhost" is the container itself, not the host or another container.
  • A firewall rejects the connection with a reset.

How to fix it

  1. Check the service is running and listening: ss -ltnp on the server.
  2. Make the service listen on 0.0.0.0 (or the right interface) if it must accept remote connections.
  3. In Docker, connect by service name or host.docker.internal instead of localhost.
Check the port from outside

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors