python network_error ai_generated true

RuntimeError: Connection refused: The server is not running or is unreachable.

ID: python/starlette-runtime-error-connection-refused

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-07-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Attempting to connect to a Starlette server that is not started or is listening on a different host/port.

generic

中文

尝试连接到未启动或正在侦听不同主机/端口的 Starlette 服务器。

Workarounds

  1. 90% success Start server with correct host and port
    uvicorn app:app --host 0.0.0.0 --port 8000
    # Then connect to http://localhost:8000
  2. 80% success Check firewall and network settings
    sudo ufw status
    # Allow port if needed: sudo ufw allow 8000

Dead Ends

Common approaches that don't work:

  1. Checking only localhost without specifying port 70% fail

    Server may be on a different port or bound to 0.0.0.0.

  2. Using wrong protocol (http vs https) 60% fail

    If server uses SSL, http connections fail.