Critical severity beginner · Fix: 2-5 min

ConnectionError

requests.exceptions.ConnectionError

What this error means
The Ollama client cannot connect because the Ollama server is not running; start the server with 'ollama serve' to fix this.

Stack trace

traceback
requests.exceptions.ConnectionError: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:

ollama.client.OllamaConnectionError: Could not connect to Ollama server. Is 'ollama serve' running?
QUICK FIX
Start the Ollama server by running 'ollama serve' in your terminal before executing your Python code.

Why it happens

The Ollama client attempts to connect to the local Ollama server but fails because the server process is not running. This usually happens if 'ollama serve' was not started or the server crashed.

Detection

Catch ConnectionError exceptions when calling Ollama client methods and log the error message indicating the server is unreachable before retrying or alerting.

Causes & fixes

1

Ollama server process is not started

✓ Fix

Run 'ollama serve' in a terminal to start the Ollama server before running your Python client code.

2

Ollama server crashed or was terminated unexpectedly

✓ Fix

Restart the Ollama server by running 'ollama serve' again and monitor logs for stability.

3

Network or firewall blocking connection to Ollama server port

✓ Fix

Ensure local firewall or network settings allow connections to the Ollama server port (usually localhost:11434).

Code: broken vs fixed

Broken - triggers the error
python
import ollama
response = ollama.chat(model="llama2", messages=[{"role": "user", "content": "Hello"}])  # Raises ConnectionError if server not running
Fixed - works correctly
python
import ollama

# Ensure Ollama server is running by starting it in a separate terminal with 'ollama serve'
response = ollama.chat(model="llama2", messages=[{"role": "user", "content": "Hello"}])  # Now works if server is running
print(response)
The fix is to ensure the Ollama server process is running before making client calls, preventing connection errors.

Workaround

Wrap Ollama client calls in try/except ConnectionError and prompt the user or script to start 'ollama serve' if the server is unreachable.

Prevention

Automate starting the Ollama server as part of your deployment or development workflow to guarantee the server is running before client requests.

Python 3.9+ · ollama >=0.1.0 · tested on 0.1.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.