ConnectionRefusedError: Connection Refused

ConnectionRefusedError: [Errno 111] Connection refused

Quick Answer

The server is not accepting connections. Check that it is running, the host and port are correct, and no firewall is blocking.

Why This Happens

This error occurs when no server is listening on the specified port. Common causes: server not running, wrong host/port, firewall blocking, or server still starting up.

The Problem

import requests
response = requests.get('http://localhost:8000/api')

The Fix

import requests
try:
    response = requests.get('http://localhost:8000/api', timeout=5)
except requests.ConnectionError:
    print('Server is not running')

Step-by-Step Fix

  1. 1

    Check if server is running

    Verify with ps aux or check the server terminal.

  2. 2

    Verify host and port

    Ensure correct host and port number.

  3. 3

    Check firewall

    Try curl or telnet to test connectivity.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free