Repository navigation
Fix ClientTransaction init crash (search returns 404) - #90
Open
Mckgare0717 wants to merge 1 commit into
Open
Mckgare0717 wants to merge 1 commit into
Mckgare0717 wants to merge 1 commit into
Conversation
x.com serves a stripped-down logged-out shell (no ondemand.s JS bundle reference) to unauthenticated requests. x_client_transaction's homepage parser (get_ondemand_file_url) expects that bundle reference and crashes with "'NoneType' object has no attribute 'group'" when its regex finds nothing, so ClientTransaction silently fails to initialize. _ensure_client_transaction already swallows that exception and continues without the x-client-transaction-id header, so most endpoints (feed, status, whoami) keep working. Twitter's search endpoint enforces the header and returns a bare 404 once it's missing, which is where this first surfaced. Fix: attach the client's own session cookies to the homepage fetch used for ClientTransaction init, same as every other authenticated request. With cookies, x.com returns the full app shell and the bundle regex matches again. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WTsyPvyhvsNrHiWBxuucUG
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
search(and any other endpoint that requiresx-client-transaction-id) currently fails with a bareHTTP 404, becauseClientTransactionsilently fails to initialize on every run._ensure_client_transactionfetcheshttps://x.comwithout the session's auth cookies to scrape theondemand.sJS bundle reference. x.com now serves a stripped-down logged-out shell (~32KB, no bundle reference) to unauthenticated requests, sox_client_transaction's regex inget_ondemand_file_urlmatches nothing and crashes with'NoneType' object has no attribute 'group'. That exception is caught and logged as a warning, so the client silently continues without the transaction header — working fine for endpoints that don't require it (feed,status,whoami), and hitting a 404 on ones that do (search).auth_token/ct0cookies to that homepage fetch, exactly like every other authenticated request already does. With cookies, x.com returns the full ~300KB+ app shell and the bundle regex matches again.Verified locally against live x.com: before the fix,
twitter search "..."reliably logsFailed to init ClientTransaction: 'NoneType' object has no attribute 'group'and returns a 404; after the fix, no warning, ClientTransaction initializes, and search returns real results.Test plan
TestEnsureClientTransactionintests/test_client.py— two tests confirming the homepage fetch carries theCookieheader (both from discreteauth_token/ct0and fromcookie_string). Verified both fail withKeyError: 'Cookie'against the pre-fix code and pass after.241 passed, same 3 pre-existing failures as onmain(test_iter_chrome_cookie_files_*intests/test_auth.py— unrelated Chrome-profile path detection tests that don't pass on Windows; unaffected by this change).twitter search,twitter status,twitter -c feedall working post-fix.