xtekky/gpt4free · error · RuntimeError

Failed to get quota information from Ollama: {e}

Error message

Failed to get quota information from Ollama: {e}

What it means

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.

Source

Thrown at g4f/Provider/local/Ollama.py:116

                        quota[key] = {
                            "used_percent": pct,
                            "reset_time": reset_time,
                        }
                    match = re.search(
                        r'<span class="text-sm">Premium requests</span>\s*<span class="text-sm">(\d+)/(\d+) used</span>\s*</div>',
                        html,
                    )
                    if match:
                        used = int(match.group(1))
                        total = int(match.group(2))
                        pct = (used / total) * 100 if total > 0 else None
                        quota["premium_requests"] = {
                            "used": used,
                            "total": total,
                            "used_percent": pct,
                        }
        except Exception as e:
            raise RuntimeError(f"Failed to get quota information from Ollama: {e}")
        if not quota:
            raise RuntimeError(
                "Failed to find quota information in Ollama settings page."
            )
        return quota

    @classmethod
    def get_models(cls, api_key: str = None, base_url: str = None, **kwargs):
        if not cls.models:
            cls.models = []
            if not api_key or AppConfig.disable_custom_api_key:
                api_key = AuthManager.load_api_key(cls)
            models = requests.get(
                "https://ollama.com/api/tags", timeout=kwargs.get("timeout", 15)
            ).json()["models"]
            if models:
                cls.live += 1
            cls.models = [model["name"] for model in models]

View on GitHub (pinned to 973504e177)

Solutions

  1. Read the {e} suffix — it names the actual exception; fix that cause (e.g. requests.exceptions.ConnectionError → network/proxy issue).
  2. Confirm network access to ollama.com from the host (curl -I https://ollama.com).
  3. Ensure a valid session cookie is configured so the settings page parses as expected (see error 91).
  4. If the page layout changed, the scraping regexes in Ollama.py need updating to the new markup.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    quota = await Ollama.get_quota(...)
except RuntimeError as e:
    logger.warning(f'Ollama quota scrape failed: {e.__cause__ or e}')
    quota = None  # quota is informational — degrade, don't fail the request

Prevention

When it happens

Trigger: 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.

Common situations: Offline or proxied environments blocking ollama.com; ollama.com serving a different page after redesign; transient 5xx followed by parsing of an error body.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/d1bdc87bc1aa27fe. Report an issue: GitHub.