Skip to content

Search returns HTTP 404: x_client_transaction cannot parse new x-web homepage (no ondemand.s bundle) #88

Done

Description

@Blanchot-Alice

Summary

twitter search fails with HTTP 404 since X finished rolling out its new x-web frontend. The x-client-transaction-id header can no longer be generated, which makes graphql endpoints that require it (SearchTimeline) return 404. Read endpoints that don't require the header still work fine.

Environment

  • twitter-cli 0.8.5 (pipx, Python 3.14.7, macOS)
  • xclienttransaction 1.0.3 (latest on PyPI)
  • Auth via explicit TWITTER_AUTH_TOKEN / TWITTER_CT0 env vars (exported from Cookie-Editor, not browser fallback)
    -HTTPS proxy in use, but geo is not a factor: authenticated reads work through the same route

Repro

$ twitter search "london" -n 2
WARNING twitter_cli.client: Failed to init ClientTransaction: 'NoneType' object has no attribute 'group'
ok: false
error:
  code: not_found
  message: 'Twitter API error (HTTP 404): Twitter API error 404: '

Same run, same credentials:

$ twitter status   # ok: true, authenticated: true
$ twitter feed -n 1        # ok: true
$ twitter user someuser    # ok: true
$ twitter tweet <url>      # ok: true

Root cause

X now serves the homepage from the new x-web client instead of the legacy react-native-web bundle tree:

  • Homepage HTML now contains data-app-env="prod" and a single entry script like https://abs.twimg.com/x-web/entry-client-logged-out-<hash>.js
  • No main.<hash>.js and no ondemand.s.<hash> references anywhere in the HTML

xclienttransaction still locates the ondemand bundle with:

ON_DEMAND_FILE_REGEX = re.compile(r",(\d+):[\"']ondemand\.s[\"']", ...)
on_demand_file_index = ON_DEMAND_FILE_REGEX.search(str(response)).group(1)  # → None.group(1) → AttributeError

So ClientTransaction init fails, requests go out without x-client-transaction-id, and graphql operations that require it return 404.

This matches the reports already filed upstream:

Expected fix

Upstream port of xclienttransaction to the x-web architecture; once released, a dependency bump here should restore search. Until then twitter-cli could consider surfacing a clearer error for search (the 404 currently looks like a bad query rather than a missing anti-automation header).

Happy to test any pre-release.

Activity

  1. qdang46 commented on Sep 16, 2026

    @qdang46

    Hi — I'm the author of a Rust port of this tool, twr — same note as on #78/#73 (same root cause family): the new x-web frontend concern from this issue is exactly why twr's resolver treats query IDs as a volatile contract (baseline → cache → rotation → live rescrape, validate-before-use, fail as classified contract-drift) rather than a TTL-cached value. Live-verified today: SearchTimeline works against current x.com including the gated Latest path that requires a fresh transaction id per request. Details in my #78 comment.

  2. shane1794 commented on Sep 23, 2026

    @shane1794

    Independent repro + a narrower diagnosis than the issue title suggests.

    Environment

    • twitter-cli 0.8.5 (pipx, Python 3.14.6, Windows 11)
    • XClientTransaction 1.0.3 (latest on PyPI)
    • Auth via explicit TWITTER_AUTH_TOKEN / TWITTER_CT0 (Cookie-Editor export, no browser fallback)

    Repro is unchanged — twitter search 404s while status / feed / user-posts / tweet all work, with the Failed to init ClientTransaction: 'NoneType' object has no attribute 'group' warning.

    Narrower root cause

    The claim that X removed ondemand.s from the homepage is not quite right. Only the logged-out root URL lost it. I probed each URL with a fresh curl_cffi session per request (a shared session carries cookies across probes and gives misleading results), then ran get_ondemand_file_url() on the response:

    URL fetched auth ondemand.s in HTML get_ondemand_file_url()
    https://x.com anonymous ❌ no AttributeError
    https://x.com + cookies ✅ yes OK
    https://x.com/home anonymous ✅ yes OK
    https://x.com/home + cookies ✅ yes OK
    https://x.com/search?q=AI&f=live anonymous ✅ yes OK
    https://x.com/search?q=AI&f=live + cookies ✅ yes OK

    So it is not the x-web frontend as a whole — it is specifically the anonymous https://x.com landing page, which now returns a ~32 KB stub with no ondemand.s marker. Every other shell (including /home fetched anonymously) still carries it and parses fine.

    Why this matters for the fix

    It means the smallest correct change is to stop bootstrapping from the anonymous root URL — no cookies are required:

    # https://x.com  ->  https://x.com/home
    home_page = cffi_session.get("https://x.com/home", headers=ct_headers, timeout=10)

    I verified this end to end: with the init fetched from /home, twitter search returns results again, and search --from <user>, -t latest, and --lang all work. Sending cookies (as several of the open PRs do) also works, but is a larger change than the bug needs and introduces a second credential-carrying request.

    Note on the pile-up: there are already 7 open PRs for this (#74, #79, #84, #86, #89, #90, #91). The table above is offered so a maintainer can pick the minimal one (#84's fallback is directionally right but keys off "homepage lacks ondemand.s", whereas the real condition is "the root anonymous page lacks it") rather than merging all seven. Happy to test whichever is chosen.

  3. 34787234-svg commented on Oct 9, 2026

    @34787234-svg

    +1 — independently reproduced on Windows 11 with twitter-cli 0.8.5 (PyPI, latest as of today).

    Setup: cookie auth via TWITTER_AUTH_TOKEN / TWITTER_CT0 env vars (Cookie-Editor export), HTTPS traffic through a local HTTP proxy (Clash, 127.0.0.1:7897).

    Works fine:

    • twitter whoami → returns the authenticated profile
    • twitter user <handle> → profiles with follower counts
    • twitter user-posts <handle> → timelines incl. media URLs
    • twitter tweet <id> → tweet + replies

    Broken:

    • twitter search <any query> → every query fails with:
      • WARNING twitter_cli.client: Failed to init ClientTransaction: 'NoneType' object has no attribute 'group'
      • Twitter API error (HTTP 0/404): Twitter API error 404:
    • The ClientTransaction init warning also prints on every command, but authenticated endpoints still work without it, so only search (and possibly other guest-transaction flows) is affected.

    Note: this machine is behind GFW-style networking; the proxy makes api.x.com reachable (all working commands prove that), so this does not look network-specific — consistent with #88's hypothesis that the homepage HTML no longer contains the bundle the regex expects (ondemand.s).

    Happy to test a candidate patch (pip install from a branch) if that helps.

  4. jmargieh commented on Oct 18, 2026

    @jmargieh
    Contributor

    Fixed here: #98

  5. oxkage commented on Oct 29, 2026

    @oxkage
    Contributor

    Adding a data point on the blast radius of this failure, because it is not only search that breaks.

    We ran 0.8.5 in a daily posting loop. The Failed to init ClientTransaction warning was printed on every command, reads kept working fine, so nothing looked wrong — but every write was going out without x-client-transaction-id. Writes came back as 344 "You have reached your daily limit" on accounts that had not posted that day, and the accounts whose writes did land were suspended a day or two later (64 Your account is suspended... on the next attempt). We lost accounts to this before we understood what was happening.

    That is the part worth fixing no matter which bootstrap fix lands here: when the header cannot be produced, the client currently degrades silently into a bot-shaped client. It should fail closed instead.

    I opened #101 for exactly that — it refuses POST when no transaction id could be generated (GET unaffected, since those endpoints do not need it), logs the init failure explicitly, and keeps TWITTER_ALLOW_UNSIGNED=1 as an opt-in escape hatch. It is deliberately independent of the bootstrap PRs (#98, #99, #89, ...), so it can land before or after any of them and turns a future regression into a loud error instead of a suspension.

    For completeness, the two root causes we measured on 0.8.5:

    • anonymous GET https://x.com → ~45 KB page, no ondemand.s at all; the same request with session cookies → ~313 KB and the parser works. That is the "cookie fix" mentioned above.
    • ON_DEMAND_HASH_PATTERN is defined with escaped quotes inside a raw string (r',{}:\"([0-9a-f]+)\"'), so it never matches even against correct HTML — it needs real quotes. Fixing only the fetch is not enough.
  6. qdang46 commented on Oct 30, 2026

    @qdang46

    Sorry for the interruption. It seems this repo might be paused/stale. I'm developing twitter_cli as a replacement — feel free to try it if you need an alternative: https://github.com/quangdang46/twitter_cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions