iflytek/astron-agent · error · ValueError

Login successful but JSESSIONID cookie not found

Error message

Login successful but JSESSIONID cookie not found

What it means

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.

Solutions

  1. Verify the login credentials in the payload (model_dump(by_alias=False)) are current and correct for the target environment.
  2. Log/inspect the response body and Set-Cookie headers to see whether login actually succeeded or returned an error page with HTTP 200.
  3. Confirm login_url targets the right environment and that no SSO redirect precedes session establishment (follow redirects explicitly if needed).
  4. If the server renamed the session cookie, update the cookie lookup key from "JSESSIONID" to the new name (or match any session-looking cookie).

Example fix

# before
jsession_id = response.cookies.get("JSESSIONID")
if not jsession_id:
    raise ValueError("Login successful but JSESSIONID cookie not found")
# after
if not response.cookies:
    raise ValueError(f"Login failed, no cookies set. Status={response.status}, body={await response.text()[:200]}")
jsession_id = response.cookies.get("JSESSIONID") or response.cookies.get("SESSION")
Defensive patterns

Strategy: try-catch

Validate before calling

def creds_ready(cfg) -> bool:
    return bool(cfg.username and cfg.password and cfg.login_url)

Try / catch

try:
    cookie = await downloader.login_and_get_cookie()
except ValueError as e:
    if 'JSESSIONID' in str(e):
        logger.error('login did not establish a session; check credentials/login_url: %s', e)
        raise ConfigDownloadError('admin 登录失败,未获得会话') from e
    raise

Prevention

When it happens

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

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/3b2f375b1606b014. Report an issue: GitHub.

Appendix: source

Thrown at core/plugin/aitools/utils/config_utils.py:66

        download_url = (
            f"{self.base_url}/config/download?"
            f"project={self.config_filter.project_name}"
            f"&cluster={self.config_filter.cluster_group}"
            f"&service={self.config_filter.service_name}"
            f"&version={self.config_filter.version}"
            f"&configName={self.config_filter.config_file}"
        )
        try:
            async with aiohttp.ClientSession() as session:
                async with session.post(
                    login_url, json=self.payload.model_dump(by_alias=False)
                ) as response:
                    response.raise_for_status()
                    jsession_id = response.cookies.get("JSESSIONID")

                    if not jsession_id:
                        raise ValueError(
                            "Login successful but JSESSIONID cookie not found"
                        )

                    self.cookie = jsession_id.value

                async with session.get(
                    download_url, cookies={"JSESSIONID": self.cookie}
                ) as response:
                    response.raise_for_status()
                    data: Dict[str, Dict[str, Any]] = await response.json()

                    content = data.get("data", {}).get("content", "")
                    config_dict = dotenv_values(stream=StringIO(content))

                    return config_dict, content
        except Exception as e:
            log.exception(f"Error downloading config from Polaris: {e}")
            raise

View on GitHub (pinned to 5e758547a8)