{"record":{"id":"7cf9a6df266e9578","repo":"HKUDS/Vibe-Trading","slug":"source-produces-a-non-ascii-http-header-name-r","errorCode":null,"errorMessage":"{source} produces a non-ASCII HTTP header ({name!r}). Use an ASCII-only header value.","messagePattern":"(.+?) produces a non-ASCII HTTP header \\((.+?)\\)\\. Use an ASCII-only header value\\.","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/src/providers/llm.py","lineNumber":773,"sourceCode":"    if not value.isascii():\n        raise RuntimeError(\n            f\"{source} contains non-ASCII characters and cannot be sent in an \"\n            \"HTTP Authorization header. Replace it with the raw provider API key \"\n            \"instead of pasted JSON, HTML, or formatted text.\"\n        )\n    if any(ord(char) < 33 or ord(char) > 126 for char in value):\n        raise RuntimeError(\n            f\"{source} contains whitespace or control characters and cannot be \"\n            \"sent in an HTTP Authorization header. Replace it with the raw \"\n            \"provider API key.\"\n        )\n\n\ndef _validate_explicit_headers(headers: Mapping[str, str], *, source: str) -> None:\n    \"\"\"Reject explicit provider headers that HTTPX cannot encode safely.\"\"\"\n    for name, value in headers.items():\n        if not name.isascii() or not value.isascii():\n            raise RuntimeError(\n                f\"{source} produces a non-ASCII HTTP header ({name!r}). \"\n                \"Use an ASCII-only header value.\"\n            )\n        if \"\\r\" in value or \"\\n\" in value:\n            raise RuntimeError(\n                f\"{source} produces an invalid multiline HTTP header ({name!r}).\"\n            )\n\n\ndef _redact_proxy_url(name: str, raw: str | None) -> str:\n    \"\"\"Return a credential-free proxy URL label.\"\"\"\n    if not raw:\n        return \"unset\"\n    if name.upper().endswith(\"NO_PROXY\"):\n        return \"set\"\n    return _redact_base_url_for_log(raw)\n\n","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/providers/llm.py#L755-L791","documentation":"Raised by _validate_explicit_headers when an explicitly configured provider header (name or value) contains non-ASCII characters. HTTPX/httpcore only accept ASCII header bytes, so encoding would fail later at request time; the library fails fast with a clear message instead.","triggerScenarios":"Passing extra_headers (e.g. via build_llm provider config) where a header name or value contains non-ASCII characters, such as a descriptive Authorization token, a Unicode organization name, or metadata copied from a browser request.","commonSituations":"Copy-pasting headers from browser devtools or curl with UTF-8 characters (e.g. 'X-Title: Vibe Trading – 分析'); non-ASCII API keys or user-agent strings; localized labels embedded in header values.","solutions":["Make the header value ASCII-only (strip/replace non-ASCII characters)","Percent-encode or base64-encode any non-ASCII payload and put it in the request body instead of a header","If the value is meant to be Unicode metadata, send it as a JSON body field rather than an HTTP header"],"exampleFix":"# before\nextra_headers = {\"X-Title\": \"Vibe Trading – 分析\"}\n\n# after\nextra_headers = {\"X-Title\": \"Vibe Trading - analytics\"}","handlingStrategy":"validation","validationCode":"def is_ascii_headers(headers: Mapping[str, str]) -> bool:\n    return all(name.isascii() and value.isascii() for name, value in headers.items())\n\nassert is_ascii_headers(extra_headers), 'headers must be ASCII'","typeGuard":"def is_ascii_headers(headers: Mapping[str, str]) -> bool:\n    return all(n.isascii() and v.isascii() for n, v in headers.items())","tryCatchPattern":null,"preventionTips":["Sanitize header values at config load: value.encode('ascii', errors='strict')","Keep Unicode metadata in the request body, never headers"],"tags":["http-headers","ascii","validation","llm-provider"],"backgroundTag":"invalid-http-header","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}