-
Notifications
You must be signed in to change notification settings - Fork 822
HTTP header validation error: trailing whitespace in platform.version() causes Connection error #1266
Copy link
Copy link
Open
Description
Bug Report: HTTP Header Validation Error Due to Trailing Whitespace in platform.version()
Environment
- kimi-cli version: 1.15.0
- Python version: 3.13.12
- OS: Ubuntu 22.04.5 LTS (Jammy)
- Kernel: 6.8.0-101-generic
Problem Description
The CLI fails with a Connection error on certain Linux systems because platform.version() returns a string with a trailing space, which violates HTTP header validation in the h11 library.
Error Message
httpcore.LocalProtocolError: Illegal header value b'#101~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 11 13:19:54 UTC '
Root Cause
In kimi_cli/auth/oauth.py, the _ascii_header_value() function does not strip whitespace from header values:
def _ascii_header_value(value: str, *, fallback: str = "unknown") -> str:
try:
value.encode("ascii")
return value # <-- Missing .strip() here
except UnicodeEncodeError:
sanitized = value.encode("ascii", errors="ignore").decode("ascii").strip()
return sanitized or fallbackOn some Linux systems, platform.version() returns:
'#101~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 11 13:19:54 UTC '
# ^
# trailing space!This value is used in X-Msh-Os-Version header via _common_headers():
"X-Msh-Os-Version": platform.version(),The h11 library (used by httpx/httpcore) validates headers against RFC 7230 and rejects values with trailing whitespace.
Steps to Reproduce
- Install kimi-cli on Ubuntu 22.04 with kernel 6.8.0-101-generic
- Run
kimi loginto authenticate - Run any command that makes an API call:
echo "hi" | kimi --print --quiet
- Observe
Connection error
Workaround / Fix
Add .strip() to the return value in _ascii_header_value():
def _ascii_header_value(value: str, *, fallback: str = "unknown") -> str:
try:
value.encode("ascii")
return value.strip() # Fixed: strip whitespace
except UnicodeEncodeError:
sanitized = value.encode("ascii", errors="ignore").decode("ascii").strip()
return sanitized or fallbackVerification
After applying the fix locally:
$ echo "hi" | kimi --print --quiet
Hey there! 👋
I'm Kimi, ready to help you with whatever you need. What's on your mind today?Additional Context
- This issue is specific to certain kernel builds where
uname -vincludes trailing whitespace - The bug affects the
X-Msh-Os-Versionheader and potentially other headers if they contain user/system data with whitespace - Related: h11's strict validation of
field-valuepattern in RFC 7230
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels