MemPalace/mempalace · error · LLMError
Cannot reach {url}: {e}
Error message
Cannot reach {url}: {e} What it means
LLMError raised when urlopen fails at the transport layer (urllib.error.URLError or OSError) before any HTTP response exists. This covers DNS failure, connection refused, timeouts, and reset connections — the message embeds the underlying exception text.
Source
Thrown at mempalace/llm_client.py:197
def _http_post_json(url: str, body: dict, headers: dict, timeout: int) -> dict:
"""POST JSON and return the parsed response. Raises LLMError on any failure."""
req = Request(
url,
data=json.dumps(body).encode("utf-8"),
headers={"Content-Type": "application/json", **headers},
)
try:
with urlopen(req, timeout=timeout) as resp:
return json.loads(resp.read())
except HTTPError as e:
detail = ""
try:
detail = e.read().decode("utf-8", errors="replace")[:500]
except Exception:
pass
raise LLMError(f"HTTP {e.code} from {url}: {detail or e.reason}") from e
except (URLError, OSError) as e:
raise LLMError(f"Cannot reach {url}: {e}") from e
except json.JSONDecodeError as e:
raise LLMError(f"Malformed response from {url}: {e}") from e
# ==================== OLLAMA ====================
class OllamaProvider(LLMProvider):
name = "ollama"
DEFAULT_ENDPOINT = "http://localhost:11434"
def __init__(
self,
model: str,
endpoint: Optional[str] = None,
timeout: int = 180,
num_ctx: Optional[int] = None,
**_: object,View on GitHub (pinned to 06cb6987f0)
Solutions
- Confirm the service is up: curl http://localhost:11434/api/tags (or your provider's health URL)
- Start the local runtime (ollama serve, LM Studio server, vLLM) and retry
- Verify --llm-endpoint host/port and that the host is reachable from where the code runs
- Increase the timeout if large prompts are cutting it close
Example fix
# before
provider = build_provider("ollama", model="qwen3:8b")
resp = provider.classify(s, u) # LLMError: Cannot reach http://localhost:11434: <urlopen error [Errno 111] Connection refused>
# after
import subprocess
subprocess.run(["ollama", "serve"]) # or ensure service is running
provider = build_provider("ollama", model="qwen3:8b")
resp = provider.classify(s, u) Defensive patterns
Strategy: retry
Validate before calling
import socket
from urllib.parse import urlparse
def endpoint_reachable(url, timeout=2):
u = urlparse(url)
host, port = u.hostname, u.port or (443 if u.scheme == "https" else 80)
try:
with socket.create_connection((host, port), timeout=timeout):
return True
except OSError:
return False
assert endpoint_reachable(provider.endpoint) Try / catch
from mempalace.llm_client import LLMError
try:
resp = provider.classify(system, user)
except LLMError as e:
if str(e).startswith("Cannot reach"):
# service down: start it or queue work for later
...
raise Prevention
- Health-check the local runtime (GET /api/tags for Ollama) at pipeline startup
- Run the LLM service and the client on the same host or verify network reachability
- Set a timeout sized for your prompt length instead of relying on defaults
When it happens
Trigger: Ollama not running (connection refused on localhost:11434); wrong hostname/port in --llm-endpoint; DNS failure for api.anthropic.com; request exceeded the configured timeout; firewall blocking the connection.
Common situations: Forgot to start Ollama/LM Studio/vLLM before running the pipeline; service listening only on 127.0.0.1 while the client runs in a container; proxy or corporate firewall blocking localhost-adjacent or external traffic; long classification requests exceeding the default 120s timeout.
Related errors
- Qdrant request failed: {exc.reason}
- HTTP {e.code} from {url}: {detail or e.reason}
- Malformed response from {url}: {e}
- Qdrant returned invalid JSON
- LLM_ENDPOINT must use http:// or https:// (got scheme {schem
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/8c09e6ae48e8d621.
Report an issue: GitHub.