{"record":{"id":"76f2e29e28410f58","repo":"xtekky/gpt4free","slug":"ollama-session-cookie-is-invalid-or-expired","errorCode":null,"errorMessage":"Ollama session cookie is invalid or expired.","messagePattern":"Ollama session cookie is invalid or expired\\.","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/local/Ollama.py","lineNumber":77,"sourceCode":"                        or \"/auth/signin\" in lower\n                        or 'href=\"/signin\"' in lower\n                        or 'href=\"/login\"' in lower\n                    )\n                    has_form = \"<form\" in lower\n                    has_password = (\n                        'type=\"password\"' in lower or 'name=\"password\"' in lower\n                    )\n                    has_email = 'type=\"email\"' in lower or 'name=\"email\"' in lower\n                    if (\n                        (\n                            has_sign_in\n                            and has_form\n                            and (has_email or has_password or has_auth_endpoint)\n                        )\n                        or (has_form and has_auth_endpoint)\n                        or (has_form and has_password and has_email)\n                    ):\n                        raise MissingAuthError(\n                            \"Ollama session cookie is invalid or expired.\"\n                        )\n                    for label in (\"Session usage\", \"Hourly usage\", \"Weekly usage\"):\n                        idx = html.find(label)\n                        if idx == -1:\n                            continue\n                        section = html[idx + len(label) : idx + len(label) + 800]\n                        pct_match = re.search(r\"(\\d+(?:\\.\\d+)?)%\\s*used\", section)\n                        if not pct_match:\n                            width_match = re.search(\n                                r\"width:\\s*(\\d+(?:\\.\\d+)?)%\", section\n                            )\n                            if width_match:\n                                pct_match = width_match\n                        pct = float(pct_match.group(1)) if pct_match else None\n                        reset_match = re.search(\n                            r'data-time=[\"\\']([^\"\\']+)[\"\\']', section\n                        )","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/local/Ollama.py#L59-L95","documentation":"MissingAuthError raised by the Ollama cloud provider while scraping the ollama.com account settings page (to read quota usage): the fetched HTML looks like a sign-in form — the code heuristically detects combinations of a form tag with password/email inputs or auth endpoints (has_sign_in/has_form/has_password/has_email/has_auth_endpoint). Receiving a login page instead of the settings page means the session cookie is missing, invalid, or expired.","triggerScenarios":"Calling Ollama methods that scrape ollama.com (quota/settings endpoints) with an api_key/session cookie that ollama.com no longer accepts; the cookie expired (sessions are time-limited); the AuthManager returned a placeholder/empty cookie; or ollama.com changed its auth flow so a valid cookie still redirects to a login page.","commonSituations":"Using an Ollama web session cookie copied weeks earlier; rotating cookies after password changes/logging out in the browser; ollama.com shipping a redesigned login/settings flow that trips the form heuristics even when authenticated.","solutions":["Log in to ollama.com in a browser, copy the fresh session cookie, and update the stored credential used by AuthManager (set the Ollama api_key/cookie again).","Verify the cookie works outside g4f: curl -s -H 'Cookie: <cookie>' https://ollama.com/settings should show the settings page, not a login form.","If ollama.com changed its markup/flow, update the provider (or g4f) to the new auth/quota surface."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import requests\nr = requests.get('https://ollama.com/settings', cookies={'session': cookie})\nif 'sign in' in r.text.lower() or r.url.endswith('/login'):\n    raise SystemExit('Ollama session cookie expired — refresh it')","typeGuard":null,"tryCatchPattern":"try:\n    quota = await Ollama.get_quota(...)\nexcept MissingAuthError:\n    # re-prompt user for a fresh ollama.com session cookie\n    ...","preventionTips":["Verify the session cookie against ollama.com/settings before batch runs.","Refresh cookies on a schedule — web sessions expire.","Catch MissingAuthError separately from parse errors so re-auth is unambiguous."],"tags":["auth","ollama","cookies","session-expired"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}