Fix twitter cookie parsing regression (#196)

Co-authored-by: Yin <mbair@gmail.com>
This commit is contained in:
Pnant
2026-03-23 18:35:47 +08:00
committed by GitHub
parent 7e66abe636
commit 0c6c45a010
2 changed files with 34 additions and 15 deletions
+22 -15
View File
@@ -913,21 +913,7 @@ def _cmd_configure(args):
# Accept two formats:
# 1. auth_token ct0 (two separate values)
# 2. Full cookie header string: "auth_token=xxx; ct0=yyy; ..."
auth_token = None
ct0 = None
if "auth_token=" in value and "ct0=" in value:
# Full cookie string — parse it
for part in value.replace(";", " ").split():
if part.startswith("auth_token="):
auth_token = part.split("=", 1)[1]
elif part.startswith("ct0="):
ct0 = part.split("=", 1)[1]
elif len(value.split()) == 2 and "=" not in value:
# Two separate values: AUTH_TOKEN CT0
parts = value.split()
auth_token = parts[0]
ct0 = parts[1]
auth_token, ct0 = _parse_twitter_cookie_input(value)
if auth_token and ct0:
config.set("twitter_auth_token", auth_token)
@@ -1009,6 +995,27 @@ def _cmd_configure(args):
print(f"✅ Groq key configured!")
def _parse_twitter_cookie_input(value: str):
"""Parse Twitter cookie input from either separate values or a cookie header."""
auth_token = None
ct0 = None
if "auth_token=" in value and "ct0=" in value:
# Full cookie string — parse it.
for part in value.replace(";", " ").split():
if part.startswith("auth_token="):
auth_token = part.split("=", 1)[1]
elif part.startswith("ct0="):
ct0 = part.split("=", 1)[1]
elif len(value.split()) == 2 and "=" not in value:
# Two separate values: AUTH_TOKEN CT0.
parts = value.split()
auth_token = parts[0]
ct0 = parts[1]
return auth_token, ct0
def _configure_xhs_cookies(value):
"""Import cookies into xiaohongshu-mcp Docker container.