{"record":{"id":"5691be0a9976c407","repo":"Fosowl/agenticSeek","slug":"http-request-failed-str-e","errorCode":null,"errorMessage":"HTTP request failed: {str(e)}","messagePattern":"HTTP request failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":412,"sourceCode":"\n            if verbose:\n                print(\"Response from LM Studio:\", result)\n            choices = result.get(\"choices\", [])\n            if not choices:\n                raise Exception(f\"No choices in LM Studio response: {result}\")\n\n            message = choices[0].get(\"message\", {})\n            content = message.get(\"content\", \"\")\n            if not content:\n                raise Exception(f\"Empty content in LM Studio response: {result}\")\n            return content\n\n        except requests.exceptions.Timeout:\n            raise Exception(\"LM Studio request timed out - check if server is responsive\")\n        except requests.exceptions.ConnectionError:\n            raise Exception(f\"Cannot connect to LM Studio at {route_start} - check if server is running\")\n        except requests.exceptions.RequestException as e:\n            raise Exception(f\"HTTP request failed: {str(e)}\") from e\n        except Exception as e:\n            if \"LM Studio\" in str(e):\n                raise  # Re-raise our custom exceptions\n            raise Exception(f\"Unexpected error: {str(e)}\") from e\n\n    def openrouter_fn(self, history, verbose=False):\n        \"\"\"\n        Use OpenRouter API to generate text.\n        \"\"\"\n        client = OpenAI(api_key=self.api_key, base_url=\"https://openrouter.ai/api/v1\")\n        if self.is_local:\n            # This case should ideally not be reached if unsafe_providers is set correctly\n            # and is_local is False in config for openrouter\n            raise Exception(\"OpenRouter is not available for local use. Change config.ini\")\n        try:\n            response = client.chat.completions.create(\n                model=self.model,\n                messages=history,","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L394-L430","documentation":"lm_studio_fn wraps any requests.exceptions.RequestException that is not a Timeout or ConnectionError into a generic 'HTTP request failed: <details>' Exception. This means the HTTP call to the local LM Studio server failed for a reason other than timeout or connection refusal (e.g. protocol error, too many redirects, SSL issue). The original exception is chained via 'from e' so the cause is preserved in the traceback.","triggerScenarios":"Calling lm_studio_fn while the POST to the LM Studio server raises a requests RequestException subclass other than Timeout/ConnectionError — e.g. invalid URL scheme in the route, chunked encoding error, too many redirects, or a proxy misconfiguration raising requests exceptions.","commonSituations":"config.ini route set to a malformed URL (missing http://, trailing bad port); a corporate proxy intercepting localhost traffic; requests library incompatibility with the local server's response; server returning a broken stream mid-transfer.","solutions":["Check the LM Studio server URL in config.ini is a well-formed http://host:port endpoint","Verify the LM Studio server is running and serving on the expected port (curl the /v1/models endpoint)","Disable any HTTP(S)_PROXY environment variables for localhost (set NO_PROXY=127.0.0.1,localhost)","Read the chained cause in the traceback for the exact requests error and address it","Upgrade requests if the error indicates a protocol/encoding bug"],"exampleFix":"// before\nroute = \"localhost:1234/v1\"  # missing scheme -> InvalidSchema (RequestException)\n// after\nroute = \"http://localhost:1234/v1\"","handlingStrategy":"try-catch","validationCode":"import requests\ndef lm_studio_reachable(url):\n    try:\n        r = requests.get(url.rstrip('/').rsplit('/chat/completions',1)[0] + '/models', timeout=5)\n        return r.ok\n    except requests.exceptions.RequestException:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    out = provider.lm_studio_fn(history)\nexcept Exception as e:\n    cause = e.__cause__\n    if isinstance(cause, requests.exceptions.RequestException):\n        log.warning(\"LM Studio HTTP failure: %s\", cause)\n    raise","preventionTips":["Pre-flight check the server /models endpoint before generating","Keep config route URLs well-formed with explicit http:// scheme","Set NO_PROXY for localhost to avoid proxy interference","Pin/upgrade the requests library version"],"tags":["network","lm-studio","http-request"],"backgroundTag":"http-request-failed","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}