Panniantong/Agent-Reach · error · ValueError

platform is required for browser-cookie extraction; choose o

Error message

platform is required for browser-cookie extraction; choose one of: {', '.join(_PLATFORM_SPECS_BY_KEY)}

What it means

Raised by _platform_spec() in agent_reach/cookie_extract.py when extract_all() is called without a platform. extract_all intentionally no longer supports reading all platforms at once (the legacy name is kept only for API compatibility); exactly one platform must be named. Valid keys come from _PLATFORM_SPECS_BY_KEY: 'twitter', 'xhs', 'bilibili', 'xueqiu'.

Source

Thrown at agent_reach/cookie_extract.py:184

    profiles = list_browser_profiles(browser)
    for candidate in profiles:
        if candidate["folder"] == profile:
            return candidate["cookies_path"]

    available = ", ".join(
        scrub_url_credentials(item["folder"]) for item in profiles
    )
    hint = f" Available profiles: {available}." if available else ""
    raise ValueError(
        f"Profile '{scrub_url_credentials(profile)}' not found for "
        f"{scrub_url_credentials(browser)}.{hint}"
    )


def _platform_spec(platform: Optional[str]) -> PlatformSpec:
    """Return the one explicitly requested platform specification."""
    if not platform:
        raise ValueError(
            "platform is required for browser-cookie extraction; "
            f"choose one of: {', '.join(_PLATFORM_SPECS_BY_KEY)}"
        )
    key = platform.lower()
    try:
        return _PLATFORM_SPECS_BY_KEY[key]
    except KeyError as exc:
        raise ValueError(
            f"Unsupported platform: {scrub_url_credentials(platform)}. "
            f"Supported: {', '.join(_PLATFORM_SPECS_BY_KEY)}"
        ) from exc


def _require_browser_extractable(spec: PlatformSpec) -> None:
    """Reject platforms whose project policy requires a manual cookie export."""
    manual_key = _COOKIE_EDITOR_ONLY.get(spec["config_key"])
    if manual_key:
        raise ValueError(

View on GitHub (pinned to 93ae1d18c3)

Solutions

  1. Pass an explicit platform keyword: extract_all(browser='chrome', platform='xueqiu')
  2. Loop over the platforms you need and call extract_all once per platform
  3. See the error text — it enumerates the supported platform keys

Example fix

# before
cookies = extract_all(browser='chrome')  # ValueError: platform is required

# after
cookies = extract_all(browser='chrome', platform='xueqiu')
Defensive patterns

Strategy: validation

Validate before calling

from agent_reach.cookie_extract import _PLATFORM_SPECS_BY_KEY
assert platform in _PLATFORM_SPECS_BY_KEY, f'pick one of {sorted(_PLATFORM_SPECS_BY_KEY)}'

Type guard

def is_supported_platform(platform: str | None) -> bool:
    return bool(platform) and platform.lower() in {'twitter', 'xhs', 'bilibili', 'xueqiu'}

Try / catch

try:
    extract_all(browser=b, platform=platform)
except ValueError as e:
    if 'platform is required' in str(e):
        platform = 'bilibili'  # choose explicitly, then retry
    else:
        raise

Prevention

When it happens

Trigger: Calling extract_all() with platform=None or omitting the keyword entirely, e.g. extract_all(browser='chrome').

Common situations: Old code written against a previous all-platform API; assuming platform is optional because the signature has a default; interactive flows that forget to pass the selected platform through.

Related errors


AI-assisted analysis of Panniantong/Agent-Reach@93ae1d18c3 (2026-08-14). Data as JSON: /api/errors/0ad635338a5b0f07. Report an issue: GitHub.