{"record":{"id":"fda2eeaf0a122861","repo":"D4Vinci/Scrapling","slug":"could-not-parse-header-without-colon-header-lin","errorCode":null,"errorMessage":"Could not parse header without colon: '{header_line}'.","messagePattern":"Could not parse header without colon: '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapling/core/utils/_shell.py","lineNumber":31,"sourceCode":"    cookie_parser = Cookie.SimpleCookie()\n    cookie_parser.load(cookie_string)\n    for key, morsel in cookie_parser.items():\n        yield key, morsel.value\n\n\ndef _ParseHeaders(header_lines: List[str], parse_cookies: bool = True) -> Tuple[Dict[str, str], Dict[str, str]]:\n    \"\"\"Parses headers into separate header and cookie dictionaries.\"\"\"\n    header_dict = dict()\n    cookie_dict = dict()\n\n    for header_line in header_lines:\n        if \":\" not in header_line:\n            if header_line.endswith(\";\"):\n                header_key = header_line[:-1].strip()\n                header_value = \"\"\n                header_dict[header_key] = header_value\n            else:\n                raise ValueError(f\"Could not parse header without colon: '{header_line}'.\")\n        else:\n            header_key, header_value = header_line.split(\":\", 1)\n            header_key = header_key.strip()\n            header_value = header_value.strip()\n\n            if parse_cookies:\n                if header_key.lower() == \"cookie\":\n                    try:\n                        cookie_dict = {key: value for key, value in _CookieParser(header_value)}\n                    except Exception as e:  # pragma: no cover\n                        raise ValueError(f\"Could not parse cookie string from header '{header_value}': {e}\")\n                else:\n                    header_dict[header_key] = header_value\n            else:\n                header_dict[header_key] = header_value\n\n    return header_dict, cookie_dict\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/core/utils/_shell.py#L13-L49","documentation":"Raised by `_ParseHeaders` in scrapling/core/utils/_shell.py:31, the parser behind the `scrapling` CLI/shell `-H/--header` flags. Each header line must either contain a colon (`Key: Value`) or end with a bare semicolon (`Key;`) which is treated as a valueless header. A line with neither a colon nor a trailing semicolon cannot be split into name/value, so a ValueError is raised with the offending line echoed.","triggerScenarios":"Running `scrapling shell -H 'Accept-Encoding gzip' url` (space instead of colon), `-H 'UserAgent: Mozilla/5.0'` without a colon after a typo, or `-H 'accept'` (bare header name without trailing `;`). Also triggered programmatically by calling `_ParseHeaders(['bad line'])`.","commonSituations":"Copying header lines from a browser 'Copy all headers' block and losing the colon; shell-quoting issues that mangle `-H` values (e.g. splitting `X-Custom: a:b` across args so only `X-Custom` survives); passing a URL accidentally as a header argument.","solutions":["Write headers in `Name: Value` form: `scrapling shell -H 'Content-Type: application/json' URL`.","For valueless headers, append a semicolon: `-H 'accept-encoding;'`.","Quote each `-H` argument fully in your shell so colons and spaces survive.","If headers come from a file, strip blank lines and lines without `:` before passing them."],"exampleFix":"# before\nscrapling shell -H 'Accept application/json' https://example.com\n\n# after\nscrapling shell -H 'Accept: application/json' https://example.com","handlingStrategy":"validation","validationCode":"def normalize_header_lines(lines: list[str]) -> list[str]:\n    out = []\n    for line in lines:\n        line = line.strip()\n        if not line:\n            continue\n        if ':' not in line and not line.endswith(';'):\n            raise ValueError(f\"Header line missing ':': {line!r}\")\n        out.append(line)\n    return out","typeGuard":null,"tryCatchPattern":"from scrapling.core.utils._shell import _ParseHeaders\ntry:\n    headers, cookies = _ParseHeaders(header_lines)\nexcept ValueError as e:\n    print(f'Fix header syntax (need \"Name: Value\" or \"Name;\"): {e}')\n    raise","preventionTips":["Always write headers as 'Name: Value' and quote the whole -H argument.","Use 'Name;' for valueless headers.","Validate header files for stray lines (URLs, blank lines) before passing them."],"tags":["cli","headers","parsing","scrapling"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}