fix(search): send auth cookies when fetching x.com home for ClientTransaction init (fixes SearchTimeline 404) - #71
Conversation
|
Thanks for tracking this down. I hit the same 404 and independently landed on the same root cause. One correction on the diagnosis though, because I think it changes which fix is the right one. The comment says the logged-in homepage is what embeds Reproducible with a completely virgin session: from curl_cffi import requests as cr
s = cr.Session(impersonate="chrome")
h = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/133.0.0.0 Safari/537.36"}
for u in ["https://x.com", "https://x.com/home"]:
r = s.get(u, headers=h, timeout=15)
print(u, "->", r.status_code, len(r.text), "ondemand:", "ondemand.s" in r.text)No What actually changed is that So the one-liner proposed by @Amirezamky9 in #69 is enough: - "https://x.com", headers=ct_headers, timeout=10,
+ "https://x.com/home", headers=ct_headers, timeout=10,I've been running this locally against 0.8.5 and Two reasons I'd prefer it over attaching cookies:
Worth noting the current diff also assumes Either way this should land soon. |
Problem
twitter search ...returns HTTP 404 for every query (with or without filters), whileuser-posts/user/tweet/feedall work. Upgrading doesn't help (PyPI 0.8.5 andmain0.8.6 share this code).Root cause
X enforces the
x-client-transaction-idanti-bot header on SearchTimeline specifically (other operations tolerate its absence, which is why onlysearch404s)._init_client_transaction()fetcheshttps://x.comwith guest headers only (no auth cookies) to locate theondemand.sfile:X's current guest homepage (~35 KB) no longer embeds the
ondemand.sreference, soget_ondemand_file_url()raises'NoneType' object has no attribute 'group'. CT init then silently fails (theWARNING Failed to init ClientTransaction: 'NoneType' ...line), nox-client-transaction-idheader is sent, and SearchTimeline returns 404.The logged-in homepage (~271 KB) still embeds
ondemand.s, so fetching it with the session cookies makes CT init succeed.I also ruled out a stale
SearchTimelinequeryId: even injecting x.com's current live queryId still 404s until the transaction-id header is present — so the header is the real cause.Fix
Send the auth cookies on the home / ondemand fetches (both use
ct_headers). This mirrors the cookie idiom already used in_build_headers:Verification
get_ondemand_file_url→NoneType.group..../ondemand.s.964027da.js), CT init OK.twitter search "openai"andtwitter search "codex" --from thsottiaux --min-likes 100return results instead of 404.