{"record":{"id":"3b2f375b1606b014","repo":"iflytek/astron-agent","slug":"login-successful-but-jsessionid-cookie-not-found","errorCode":null,"errorMessage":"Login successful but JSESSIONID cookie not found","messagePattern":"Login successful but JSESSIONID cookie not found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/utils/config_utils.py","lineNumber":66,"sourceCode":"\n        download_url = (\n            f\"{self.base_url}/config/download?\"\n            f\"project={self.config_filter.project_name}\"\n            f\"&cluster={self.config_filter.cluster_group}\"\n            f\"&service={self.config_filter.service_name}\"\n            f\"&version={self.config_filter.version}\"\n            f\"&configName={self.config_filter.config_file}\"\n        )\n        try:\n            async with aiohttp.ClientSession() as session:\n                async with session.post(\n                    login_url, json=self.payload.model_dump(by_alias=False)\n                ) as response:\n                    response.raise_for_status()\n                    jsession_id = response.cookies.get(\"JSESSIONID\")\n\n                    if not jsession_id:\n                        raise ValueError(\n                            \"Login successful but JSESSIONID cookie not found\"\n                        )\n\n                    self.cookie = jsession_id.value\n\n                async with session.get(\n                    download_url, cookies={\"JSESSIONID\": self.cookie}\n                ) as response:\n                    response.raise_for_status()\n                    data: Dict[str, Dict[str, Any]] = await response.json()\n\n                    content = data.get(\"data\", {}).get(\"content\", \"\")\n                    config_dict = dotenv_values(stream=StringIO(content))\n\n                    return config_dict, content\n        except Exception as e:\n            log.exception(f\"Error downloading config from Polaris: {e}\")\n            raise","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/utils/config_utils.py#L48-L84","documentation":"During config download, the utility logs into a remote admin system via POST and expects the response to set a JSESSIONID session cookie. If login returned HTTP 200 (raise_for_status passed) but no JSESSIONID cookie is present, a ValueError is raised because every subsequent authenticated request depends on that cookie. This typically means the login silently failed or the server uses a different session mechanism.","triggerScenarios":"POSTing the login payload to login_url succeeds at HTTP level but the response carries no JSESSIONID cookie — wrong credentials that the server handles with a 200 + error page, changed login endpoint/session cookie name, a redirect to an SSO page, or the cookie domain/path hiding it from the client's cookie jar.","commonSituations":"Password rotated or account locked so login fails softly; server upgraded and renamed the cookie or moved to token auth; login URL pointing at an environment (e.g. prod vs test) with SSO in front; proxy stripping Set-Cookie headers.","solutions":["Verify the login credentials in the payload (model_dump(by_alias=False)) are current and correct for the target environment.","Log/inspect the response body and Set-Cookie headers to see whether login actually succeeded or returned an error page with HTTP 200.","Confirm login_url targets the right environment and that no SSO redirect precedes session establishment (follow redirects explicitly if needed).","If the server renamed the session cookie, update the cookie lookup key from \"JSESSIONID\" to the new name (or match any session-looking cookie)."],"exampleFix":"# before\njsession_id = response.cookies.get(\"JSESSIONID\")\nif not jsession_id:\n    raise ValueError(\"Login successful but JSESSIONID cookie not found\")\n# after\nif not response.cookies:\n    raise ValueError(f\"Login failed, no cookies set. Status={response.status}, body={await response.text()[:200]}\")\njsession_id = response.cookies.get(\"JSESSIONID\") or response.cookies.get(\"SESSION\")","handlingStrategy":"try-catch","validationCode":"def creds_ready(cfg) -> bool:\n    return bool(cfg.username and cfg.password and cfg.login_url)","typeGuard":null,"tryCatchPattern":"try:\n    cookie = await downloader.login_and_get_cookie()\nexcept ValueError as e:\n    if 'JSESSIONID' in str(e):\n        logger.error('login did not establish a session; check credentials/login_url: %s', e)\n        raise ConfigDownloadError('admin 登录失败，未获得会话') from e\n    raise","preventionTips":["Rotate/verify admin credentials whenever environments change.","Log response body and cookies on login to detect soft-failed logins (HTTP 200 + error page).","Pin login_url per environment in configuration, not hardcoded defaults.","Watch for server-side auth upgrades (cookie renames, token auth) and update the lookup accordingly."],"tags":["authentication","http","session-cookie","config"],"backgroundTag":"authentication-required","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}