{"record":{"id":"0ad635338a5b0f07","repo":"Panniantong/Agent-Reach","slug":"platform-is-required-for-browser-cookie-extraction","errorCode":null,"errorMessage":"platform is required for browser-cookie extraction; choose one of: {', '.join(_PLATFORM_SPECS_BY_KEY)}","messagePattern":"platform is required for browser-cookie extraction; choose one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent_reach/cookie_extract.py","lineNumber":184,"sourceCode":"    profiles = list_browser_profiles(browser)\n    for candidate in profiles:\n        if candidate[\"folder\"] == profile:\n            return candidate[\"cookies_path\"]\n\n    available = \", \".join(\n        scrub_url_credentials(item[\"folder\"]) for item in profiles\n    )\n    hint = f\" Available profiles: {available}.\" if available else \"\"\n    raise ValueError(\n        f\"Profile '{scrub_url_credentials(profile)}' not found for \"\n        f\"{scrub_url_credentials(browser)}.{hint}\"\n    )\n\n\ndef _platform_spec(platform: Optional[str]) -> PlatformSpec:\n    \"\"\"Return the one explicitly requested platform specification.\"\"\"\n    if not platform:\n        raise ValueError(\n            \"platform is required for browser-cookie extraction; \"\n            f\"choose one of: {', '.join(_PLATFORM_SPECS_BY_KEY)}\"\n        )\n    key = platform.lower()\n    try:\n        return _PLATFORM_SPECS_BY_KEY[key]\n    except KeyError as exc:\n        raise ValueError(\n            f\"Unsupported platform: {scrub_url_credentials(platform)}. \"\n            f\"Supported: {', '.join(_PLATFORM_SPECS_BY_KEY)}\"\n        ) from exc\n\n\ndef _require_browser_extractable(spec: PlatformSpec) -> None:\n    \"\"\"Reject platforms whose project policy requires a manual cookie export.\"\"\"\n    manual_key = _COOKIE_EDITOR_ONLY.get(spec[\"config_key\"])\n    if manual_key:\n        raise ValueError(","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/cookie_extract.py#L166-L202","documentation":"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'.","triggerScenarios":"Calling extract_all() with platform=None or omitting the keyword entirely, e.g. extract_all(browser='chrome').","commonSituations":"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.","solutions":["Pass an explicit platform keyword: extract_all(browser='chrome', platform='xueqiu')","Loop over the platforms you need and call extract_all once per platform","See the error text — it enumerates the supported platform keys"],"exampleFix":"# before\ncookies = extract_all(browser='chrome')  # ValueError: platform is required\n\n# after\ncookies = extract_all(browser='chrome', platform='xueqiu')","handlingStrategy":"validation","validationCode":"from agent_reach.cookie_extract import _PLATFORM_SPECS_BY_KEY\nassert platform in _PLATFORM_SPECS_BY_KEY, f'pick one of {sorted(_PLATFORM_SPECS_BY_KEY)}'","typeGuard":"def is_supported_platform(platform: str | None) -> bool:\n    return bool(platform) and platform.lower() in {'twitter', 'xhs', 'bilibili', 'xueqiu'}","tryCatchPattern":"try:\n    extract_all(browser=b, platform=platform)\nexcept ValueError as e:\n    if 'platform is required' in str(e):\n        platform = 'bilibili'  # choose explicitly, then retry\n    else:\n        raise","preventionTips":["Treat platform as a required argument in your wrappers","Call extract_all once per platform in a loop instead of expecting a multi-platform result"],"tags":["cookies","api-contract","validation"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}