From 1f267008ad851cafaa92d3e2b208655b3b0930e2 Mon Sep 17 00:00:00 2001 From: jackwener Date: Wed, 11 Mar 2026 00:45:13 +0800 Subject: [PATCH] fix: update stale Followers/Following queryIds and retry on 422 Twitter now returns HTTP 422 GRAPHQL_VALIDATION_FAILED (not just 404) when a queryId goes stale. Updated fallback IDs and added 422 to the stale-queryId retry logic in both _graphql_get and _graphql_post. --- twitter_cli/client.py | 10 +++++----- twitter_cli/graphql.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/twitter_cli/client.py b/twitter_cli/client.py index 6798716..b667f78 100644 --- a/twitter_cli/client.py +++ b/twitter_cli/client.py @@ -654,9 +654,9 @@ class TwitterClient: try: return self._api_get(url) except TwitterAPIError as exc: - # Fallback query IDs can go stale. Retry with live lookup if 404. - if exc.status_code == 404 and using_fallback: - logger.info("Retrying %s with live queryId after 404", operation_name) + # Fallback query IDs can go stale. Retry with live lookup if 404/422. + if exc.status_code in (404, 422) and using_fallback: + logger.info("Retrying %s with live queryId after %d", operation_name, exc.status_code) _invalidate_query_id(operation_name) refreshed_query_id = _resolve_query_id(operation_name, prefer_fallback=False, url_fetch_fn=_url_fetch) retry_url = _build_graphql_url(refreshed_query_id, operation_name, variables, features, field_toggles) @@ -680,8 +680,8 @@ class TwitterClient: try: return _do_post(query_id) except TwitterAPIError as exc: - if exc.status_code == 404 and using_fallback: - logger.info("Retrying POST %s with live queryId after 404", operation_name) + if exc.status_code in (404, 422) and using_fallback: + logger.info("Retrying POST %s with live queryId after %d", operation_name, exc.status_code) _invalidate_query_id(operation_name) refreshed = _resolve_query_id(operation_name, prefer_fallback=False, url_fetch_fn=_url_fetch) return _do_post(refreshed) diff --git a/twitter_cli/graphql.py b/twitter_cli/graphql.py index aaf9c7c..50f7fcd 100644 --- a/twitter_cli/graphql.py +++ b/twitter_cli/graphql.py @@ -33,8 +33,8 @@ FALLBACK_QUERY_IDS = { "SearchTimeline": "MJpyQGqgklrVl_0X9gNy3A", "Bookmarks": "uzboyXSHSJrR-mGJqep0TQ", "ListLatestTweetsTimeline": "ZBbXrl0FVnTqp7K6EAADog", - "Followers": "t-BPOrMIduGUJWO_LxcvNQ", - "Following": "iSicc7LrzWGBgDPL0tM_TQ", + "Followers": "IOh4aS6UdGWGJUYTqliQ7Q", + "Following": "zx6e-TLzRkeDO_a7p4b3JQ", "CreateTweet": "bDE2rBtZb3uyrczSZ_pI9g", "DeleteTweet": "VaenaVgh5q5ih7kvyVjgtg", "FavoriteTweet": "lI07N6Otwv1PhnEgXILM7A",