{"record":{"id":"d1bdc87bc1aa27fe","repo":"xtekky/gpt4free","slug":"failed-to-get-quota-information-from-ollama-e","errorCode":null,"errorMessage":"Failed to get quota information from Ollama: {e}","messagePattern":"Failed to get quota information from Ollama: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/local/Ollama.py","lineNumber":116,"sourceCode":"                        quota[key] = {\n                            \"used_percent\": pct,\n                            \"reset_time\": reset_time,\n                        }\n                    match = re.search(\n                        r'<span class=\"text-sm\">Premium requests</span>\\s*<span class=\"text-sm\">(\\d+)/(\\d+) used</span>\\s*</div>',\n                        html,\n                    )\n                    if match:\n                        used = int(match.group(1))\n                        total = int(match.group(2))\n                        pct = (used / total) * 100 if total > 0 else None\n                        quota[\"premium_requests\"] = {\n                            \"used\": used,\n                            \"total\": total,\n                            \"used_percent\": pct,\n                        }\n        except Exception as e:\n            raise RuntimeError(f\"Failed to get quota information from Ollama: {e}\")\n        if not quota:\n            raise RuntimeError(\n                \"Failed to find quota information in Ollama settings page.\"\n            )\n        return quota\n\n    @classmethod\n    def get_models(cls, api_key: str = None, base_url: str = None, **kwargs):\n        if not cls.models:\n            cls.models = []\n            if not api_key or AppConfig.disable_custom_api_key:\n                api_key = AuthManager.load_api_key(cls)\n            models = requests.get(\n                \"https://ollama.com/api/tags\", timeout=kwargs.get(\"timeout\", 15)\n            ).json()[\"models\"]\n            if models:\n                cls.live += 1\n            cls.models = [model[\"name\"] for model in models]","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/local/Ollama.py#L98-L134","documentation":"RuntimeError wrapping ANY unexpected exception raised inside the Ollama quota-scraping try block (the block that GETs the settings page and regex-parses usage percentages and premium-request counters). It is a catch-all: the chained {e} is the real error — network failure, TLS error, regex/attribute errors, parser bugs — flattened into one message.","triggerScenarios":"Network-level failures fetching ollama.com (DNS, timeout, proxy refusal); HTML parsing code raising (None from a regex search being mis-indexed); an unexpected content type (JSON/redirect) where string methods fail; or downstream code raising on a page shape the scraper did not anticipate.","commonSituations":"Offline or proxied environments blocking ollama.com; ollama.com serving a different page after redesign; transient 5xx followed by parsing of an error body.","solutions":["Read the {e} suffix — it names the actual exception; fix that cause (e.g. requests.exceptions.ConnectionError → network/proxy issue).","Confirm network access to ollama.com from the host (curl -I https://ollama.com).","Ensure a valid session cookie is configured so the settings page parses as expected (see error 91).","If the page layout changed, the scraping regexes in Ollama.py need updating to the new markup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    quota = await Ollama.get_quota(...)\nexcept RuntimeError as e:\n    logger.warning(f'Ollama quota scrape failed: {e.__cause__ or e}')\n    quota = None  # quota is informational — degrade, don't fail the request","preventionTips":["Treat quota info as optional: wrap and degrade instead of failing chat requests.","Ensure outbound network access to ollama.com from the runtime host.","Log the chained cause to separate network vs parser failures."],"tags":["ollama","quota","scraping","wrapper"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}