{"record":{"id":"8c09e6ae48e8d621","repo":"MemPalace/mempalace","slug":"cannot-reach-url-e","errorCode":null,"errorMessage":"Cannot reach {url}: {e}","messagePattern":"Cannot reach (.+?): (.+?)","errorType":"exception","errorClass":"LLMError","httpStatus":null,"severity":"error","filePath":"mempalace/llm_client.py","lineNumber":197,"sourceCode":"def _http_post_json(url: str, body: dict, headers: dict, timeout: int) -> dict:\n    \"\"\"POST JSON and return the parsed response. Raises LLMError on any failure.\"\"\"\n    req = Request(\n        url,\n        data=json.dumps(body).encode(\"utf-8\"),\n        headers={\"Content-Type\": \"application/json\", **headers},\n    )\n    try:\n        with urlopen(req, timeout=timeout) as resp:\n            return json.loads(resp.read())\n    except HTTPError as e:\n        detail = \"\"\n        try:\n            detail = e.read().decode(\"utf-8\", errors=\"replace\")[:500]\n        except Exception:\n            pass\n        raise LLMError(f\"HTTP {e.code} from {url}: {detail or e.reason}\") from e\n    except (URLError, OSError) as e:\n        raise LLMError(f\"Cannot reach {url}: {e}\") from e\n    except json.JSONDecodeError as e:\n        raise LLMError(f\"Malformed response from {url}: {e}\") from e\n\n\n# ==================== OLLAMA ====================\n\n\nclass OllamaProvider(LLMProvider):\n    name = \"ollama\"\n    DEFAULT_ENDPOINT = \"http://localhost:11434\"\n\n    def __init__(\n        self,\n        model: str,\n        endpoint: Optional[str] = None,\n        timeout: int = 180,\n        num_ctx: Optional[int] = None,\n        **_: object,","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/llm_client.py#L179-L215","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nprovider = build_provider(\"ollama\", model=\"qwen3:8b\")\nresp = provider.classify(s, u)  # LLMError: Cannot reach http://localhost:11434: <urlopen error [Errno 111] Connection refused>\n\n# after\nimport subprocess\nsubprocess.run([\"ollama\", \"serve\"])  # or ensure service is running\nprovider = build_provider(\"ollama\", model=\"qwen3:8b\")\nresp = provider.classify(s, u)","handlingStrategy":"retry","validationCode":"import socket\nfrom urllib.parse import urlparse\n\ndef endpoint_reachable(url, timeout=2):\n    u = urlparse(url)\n    host, port = u.hostname, u.port or (443 if u.scheme == \"https\" else 80)\n    try:\n        with socket.create_connection((host, port), timeout=timeout):\n            return True\n    except OSError:\n        return False\n\nassert endpoint_reachable(provider.endpoint)","typeGuard":null,"tryCatchPattern":"from mempalace.llm_client import LLMError\n\ntry:\n    resp = provider.classify(system, user)\nexcept LLMError as e:\n    if str(e).startswith(\"Cannot reach\"):\n        # service down: start it or queue work for later\n        ...\n    raise","preventionTips":["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"],"tags":["network","llm","connection","local-runtime"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}