{"record":{"id":"793c9da218a14831","repo":"D4Vinci/Scrapling","slug":"could-not-parse-cookies-cookies-err","errorCode":null,"errorMessage":"Could not parse cookies '{cookies}': {err}","messagePattern":"Could not parse cookies '(.+?)': (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapling/cli.py","lineNumber":75,"sourceCode":"\n    if ai_targeted:\n        kwargs.setdefault(\"block_ads\", True)\n    response = fetcher_func(url, **kwargs)\n    Convertor.write_content_to_file(response, str(output_path), css_selector, main_content_only=ai_targeted)\n    log.info(f\"Content successfully saved to '{output_path}'\")\n\n\ndef __ParseExtractArguments(\n    headers: List[str], cookies: str, params: str, json: Optional[str] = None\n) -> Tuple[Dict[str, str], Dict[str, str], Dict[str, str], Optional[Dict[str, str]]]:\n    \"\"\"Parse arguments for extract command\"\"\"\n    parsed_headers, parsed_cookies = _ParseHeaders(headers)\n    if cookies:\n        for key, value in _CookieParser(cookies):\n            try:\n                parsed_cookies[key] = value\n            except Exception as err:\n                raise ValueError(f\"Could not parse cookies '{cookies}': {err}\")\n\n    parsed_json = __ParseJSONData(json)\n    parsed_params = {}\n    for param in params:\n        if \"=\" in param:\n            key, value = param.split(\"=\", 1)\n            parsed_params[key] = value\n\n    return parsed_headers, parsed_cookies, parsed_params, parsed_json\n\n\ndef __BuildRequest(headers: List[str], cookies: str, params: str, json: Optional[str] = None, **kwargs) -> Dict:\n    \"\"\"Build a request object using the specified arguments\"\"\"\n    # Parse parameters\n    parsed_headers, parsed_cookies, parsed_params, parsed_json = __ParseExtractArguments(headers, cookies, params, json)\n    # Build request arguments\n    request_kwargs: Dict[str, Any] = {\n        \"headers\": parsed_headers if parsed_headers else None,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/cli.py#L57-L93","documentation":"When the CLI's cookie option is used, each parsed key/value pair is inserted into the cookie dict inside a try/except; any failure while assigning a cookie re-raised as ValueError with the offending cookie string. In practice this wraps parser failures from _CookieParser, so it means the cookie string could not be interpreted as cookies.","triggerScenarios":"Passing a malformed cookie string to `scrapling fetch URL --cookies ...`, e.g. missing '=' separator, stray quotes, or a whole Set-Cookie header (with attributes like Path=/; HttpOnly) pasted where a simple 'k=v; k2=v2' string is expected.","commonSituations":"Copying a full Set-Cookie header from DevTools instead of the Cookie request header, unterminated quoting in shell scripts, or separators other than ';' between pairs.","solutions":["Use plain 'key=value' pairs separated by ';', e.g. --cookies 'session=abc123; token=xyz'","Strip Set-Cookie-only attributes (Path, Domain, Expires, HttpOnly, Secure) before passing","Check shell quoting: the whole cookie string should be one argument","If the header is complex, pass cookies via the headers option as a Cookie header instead"],"exampleFix":"# before\nscrapling fetch https://example.com --cookies \"session=abc; Path=/; HttpOnly\"\n# ValueError: Could not parse cookies ...\n\n# after\nscrapling fetch https://example.com --cookies 'session=abc'","handlingStrategy":"validation","validationCode":"def normalize_cookies(cookie_str: str) -> str:\n    skip = {'path', 'domain', 'expires', 'max-age', 'httponly', 'secure', 'samesite'}\n    pairs = [p.strip() for p in cookie_str.split(';') if '=' in p]\n    keep = [p for p in pairs if p.split('=', 1)[0].strip().lower() not in skip]\n    return '; '.join(keep)\n\ncookies = normalize_cookies('session=abc; Path=/; HttpOnly')  # 'session=abc'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy the Cookie request header from DevTools, not a Set-Cookie response header","Keep the format strictly 'k=v; k2=v2'","Prefer the headers option when cookies get complex"],"tags":["cli","cookies","input-validation"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}