# How to Troubleshoot Ollama Server Connection Issues in MoneyPrinterV2

> Troubleshoot Ollama server connection issues in MoneyPrinterV2. Verify Ollama is running, check config.json for the correct ollama_base_url, and ensure your model is pulled before starting.

- Repository: [FujiwaraChoki/MoneyPrinterV2](https://github.com/FujiwaraChoki/MoneyPrinterV2)
- Tags: how-to-guide
- Published: 2026-03-20

---

**Ensure Ollama is running with `ollama serve`, verify [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) contains the correct `ollama_base_url` (default `http://127.0.0.1:11434`), and confirm your target model is pulled using `ollama list` before starting MoneyPrinterV2.**

MoneyPrinterV2 relies on the Ollama local LLM server to generate video content scripts. When the application cannot establish a connection to Ollama, content generation halts completely. This guide explains the connection architecture in `FujiwaraChoki/MoneyPrinterV2` and provides systematic troubleshooting steps based on the source code implementation.

## Understanding the Ollama Connection Architecture

### Configuration Layer in config.py

The connection parameters originate in [`src/config.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/config.py). This module reads [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) and exposes two critical functions: `get_ollama_base_url()` and `get_ollama_model()`. By default, `ollama_base_url` resolves to `http://127.0.0.1:11434`【/src/config.py L72-L90】.

### Client Initialization in llm_provider.py

The [`src/llm_provider.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/llm_provider.py) file constructs the actual Ollama client instance. It imports the base URL via `get_ollama_base_url()` and instantiates `ollama.Client` with this endpoint【/src/llm_provider.py L1-L9】.

### Model Validation in main.py

During application startup, [`src/main.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/main.py) performs strict validation. It calls `get_ollama_model()` and checks server availability. If the Ollama server reports no available models, the application aborts immediately with an error message at lines 448-460【/src/main.py L448-L460】.

### Pre-flight Checks in preflight_local.py

The [`scripts/preflight_local.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/scripts/preflight_local.py) script provides proactive diagnostics. It performs a health check against the configured base URL and warns when the server reports no models, allowing you to fix issues before launching the main application【/scripts/preflight_local.py L67-L80】.

## Common Connection Failure Points

When MoneyPrinterV2 fails to connect to Ollama, the issue typically falls into one of these categories:

- **Server not running** – The Ollama process is not active, causing immediate "connection refused" or timeout errors from the client.
- **Incorrect base URL** – The client points to the wrong host or port, commonly occurring in Docker environments where the container IP differs from localhost.
- **Network restrictions** – Firewalls or VPNs block port 11434, preventing the HTTP connection from establishing.
- **Model not pulled** – The application aborts with "No models found on Ollama" because the target model was never downloaded.
- **Corrupt configuration** – [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) contains malformed JSON or missing required keys, causing the configuration layer to fail.

## Step-by-Step Troubleshooting Guide

Follow these steps in order to diagnose and resolve Ollama connection issues in MoneyPrinterV2:

1. **Run the pre-flight script** – Execute the diagnostic script to surface connectivity problems before the main application starts:
   ```bash
   python3 scripts/preflight_local.py
   ```

2. **Confirm the server endpoint** – Verify that Ollama is listening on the expected port. Use curl to test the tags endpoint:
   ```bash
   curl http://127.0.0.1:11434/api/tags
   ```

   A successful response returns JSON containing available models.

3. **Check the model name** – Ensure the model specified in [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) matches an entry in the Ollama server. List installed models:
   ```bash
   ollama list
   ```

   If the model is missing, pull it: `ollama pull llama3.2:3b`.

4. **Validate configuration** – Verify that [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) contains valid JSON with both required keys:
   ```json
   {
       "ollama_base_url": "http://127.0.0.1:11434",
       "ollama_model": "llama3.2:3b"
   }
   ```

5. **Restart the application** – After fixing any of the above issues, launch MoneyPrinterV2 again:
   ```bash
   python3 src/main.py
   ```

## Diagnostic Code Examples

Use these Python snippets to programmatically verify your Ollama setup within the MoneyPrinterV2 environment:

**Programmatic health check:**

```python
import requests
from src.config import get_ollama_base_url

def ollama_health():
    url = f"{get_ollama_base_url().rstrip('/')}/api/tags"
    try:
        resp = requests.get(url, timeout=5)
        resp.raise_for_status()
        print("Ollama reachable – models:", [m["name"] for m in resp.json()["models"]])
    except Exception as e:
        print("Failed to reach Ollama:", e)

ollama_health()

```

**Inspecting the configured model:**

```python
from src.config import get_ollama_model

model = get_ollama_model()
if not model:
    raise RuntimeError("Ollama model not set in config.json")
print("Configured Ollama model:", model)

```

## Summary

- MoneyPrinterV2 connects to Ollama through [`src/config.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/config.py), which reads `ollama_base_url` and `ollama_model` from [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json).
- Connection failures typically stem from the Ollama server not running, incorrect base URLs, network blocks on port 11434, or missing models.
- Use [`scripts/preflight_local.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/scripts/preflight_local.py) to diagnose issues before launching the main application.
- Verify connectivity using `curl http://127.0.0.1:11434/api/tags` and ensure the target model appears in `ollama list`.

## Frequently Asked Questions

### Why does MoneyPrinterV2 fail immediately on startup with a connection error?

The application aborts during initialization in [`src/main.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/main.py) lines 448-460 when it cannot validate the Ollama model. This occurs when the server is unreachable, the base URL is misconfigured, or the specified model has not been pulled to the local machine.

### Can I use a remote Ollama server instead of localhost?

Yes. Modify the `ollama_base_url` value in [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) to point to your remote host, such as `http://192.168.1.100:11434` or a Docker container IP. Ensure port 11434 is open on the remote host and any firewalls between the client and server allow the connection.

### How do I verify which model MoneyPrinterV2 is trying to use?

Import `get_ollama_model()` from [`src/config.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/config.py) and print its return value, or check the `ollama_model` key directly in your [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json) file. The value must match an entry shown in the `ollama list` command output.

### What does the preflight_local.py script check?

The script performs a health check against the Ollama server using the base URL configured in [`config.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/config.json). It verifies HTTP connectivity to the `/api/tags` endpoint and warns if the server reports no available models, allowing you to resolve issues before running [`src/main.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/main.py).