Skip to content

fix: fetch authenticated /home for ClientTransaction init (new x-web frontend broke posting) - #80

Closed
zengbo wants to merge 1 commit into
public-clis:mainfrom
zengbo:fix/ct-init-authed-home
Closed

fix: fetch authenticated /home for ClientTransaction init (new x-web frontend broke posting)#80
zengbo wants to merge 1 commit into
public-clis:mainfrom
zengbo:fix/ct-init-authed-home

Conversation

@zengbo

@zengbo zengbo commented Aug 3, 2026

Copy link
Copy Markdown

Problem

Since early August 2026, every invocation logs:

WARNING twitter_cli.client: Failed to init ClientTransaction: 'NoneType' object has no attribute 'group'

and CreateTweet fails most of the time with Twitter API error (HTTP 0): Failed to create tweet (a small fraction of posts slip through), while all read endpoints keep working.

Root cause

Logged-out x.com now serves X's new x-web frontend (assets under abs.twimg.com/x-web/x-web/). That page no longer references ondemand.s.<hash>.js, so x_client_transaction.get_ondemand_file_url raises (ON_DEMAND_FILE_REGEX finds no match — the .group on None). Without a ClientTransaction, requests go out with no X-Client-Transaction-Id header and X rejects tweet creation. Upstream xclienttransaction 1.0.3 (latest) has no fix yet.

Fix

The authenticated /home page still serves the legacy responsive-web frontend containing all three signing inputs (twitter-site-verification meta, loading-x-anim SVGs, ondemand.s reference). This PR makes _ensure_client_transaction fetch https://x.com/home with the session's auth cookies. Auth is always available at that point since init runs from TwitterClient.__init__. The cache path is unaffected (it stores raw HTML/JS and bypasses get_ondemand_file_url).

Verification

  • Warning gone; ClientTransaction initialized logged.
  • twitter post + twitter delete round-trip succeeds (was failing with HTTP 0 before).
  • Read endpoints unaffected.

Note: if/when X migrates the logged-in page to x-web as well, the regexes will need a real update in xclienttransaction; this keeps the CLI working until then.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Aa1vBaCBrYHvoBgp8SZLoV

Logged-out x.com now serves the new x-web frontend (assets under
abs.twimg.com/x-web/x-web/), which no longer references
ondemand.s.<hash>.js. x-client-transaction needs that file plus the
homepage verification meta and loading-x-anim SVGs to generate the
X-Client-Transaction-Id header; without it CreateTweet fails with
'HTTP 0: Failed to create tweet' while read endpoints keep working.

The authenticated /home page still serves the legacy responsive-web
frontend with all signing inputs, so fetch it with the session's auth
cookies. Auth is always available here since _ensure_client_transaction
runs from TwitterClient.__init__.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aa1vBaCBrYHvoBgp8SZLoV
@zengbo

zengbo commented Aug 3, 2026

Copy link
Copy Markdown
Author

Closing as duplicate — #79 (2 days earlier) makes the same change, and #74 is an even more minimal fix that also comes with tests.

Some verification data points that may help triage, from debugging this independently today:

  • Root cause confirmed: logged-out https://x.com (root) now serves the new x-web frontend (abs.twimg.com/x-web/x-web/) with no ondemand.s reference, which is exactly where ON_DEMAND_FILE_REGEX.search(...).group(1) throws.
  • I just tested unauthenticated GET https://x.com/home with a Chrome-impersonated TLS session: it returns 200 with the legacy responsive-web frontend, including the ondemand.s reference, verification meta, and loading-x-anim SVGs. So fix: bootstrap ClientTransaction from responsive home #74's cookie-less URL change is sufficient on its own; the auth cookies in fix: send auth cookies when fetching x.com home for ClientTransaction init (fixes #78) #79 and this PR are not strictly required.
  • End-to-end verified on a live account: with the /home bootstrap, ClientTransaction initializes cleanly and CreateTweet succeeds again (was failing with HTTP 0: Failed to create tweet on ~8/9 attempts before).

@zengbo zengbo closed this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant