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.
This commit is contained in:
jackwener
2026-03-11 00:45:13 +08:00
parent 5c1015f1fd
commit 1f267008ad
2 changed files with 7 additions and 7 deletions

View File

@@ -654,9 +654,9 @@ class TwitterClient:
try: try:
return self._api_get(url) return self._api_get(url)
except TwitterAPIError as exc: except TwitterAPIError as exc:
# Fallback query IDs can go stale. Retry with live lookup if 404. # Fallback query IDs can go stale. Retry with live lookup if 404/422.
if exc.status_code == 404 and using_fallback: if exc.status_code in (404, 422) and using_fallback:
logger.info("Retrying %s with live queryId after 404", operation_name) logger.info("Retrying %s with live queryId after %d", operation_name, exc.status_code)
_invalidate_query_id(operation_name) _invalidate_query_id(operation_name)
refreshed_query_id = _resolve_query_id(operation_name, prefer_fallback=False, url_fetch_fn=_url_fetch) 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) retry_url = _build_graphql_url(refreshed_query_id, operation_name, variables, features, field_toggles)
@@ -680,8 +680,8 @@ class TwitterClient:
try: try:
return _do_post(query_id) return _do_post(query_id)
except TwitterAPIError as exc: except TwitterAPIError as exc:
if exc.status_code == 404 and using_fallback: if exc.status_code in (404, 422) and using_fallback:
logger.info("Retrying POST %s with live queryId after 404", operation_name) logger.info("Retrying POST %s with live queryId after %d", operation_name, exc.status_code)
_invalidate_query_id(operation_name) _invalidate_query_id(operation_name)
refreshed = _resolve_query_id(operation_name, prefer_fallback=False, url_fetch_fn=_url_fetch) refreshed = _resolve_query_id(operation_name, prefer_fallback=False, url_fetch_fn=_url_fetch)
return _do_post(refreshed) return _do_post(refreshed)

View File

@@ -33,8 +33,8 @@ FALLBACK_QUERY_IDS = {
"SearchTimeline": "MJpyQGqgklrVl_0X9gNy3A", "SearchTimeline": "MJpyQGqgklrVl_0X9gNy3A",
"Bookmarks": "uzboyXSHSJrR-mGJqep0TQ", "Bookmarks": "uzboyXSHSJrR-mGJqep0TQ",
"ListLatestTweetsTimeline": "ZBbXrl0FVnTqp7K6EAADog", "ListLatestTweetsTimeline": "ZBbXrl0FVnTqp7K6EAADog",
"Followers": "t-BPOrMIduGUJWO_LxcvNQ", "Followers": "IOh4aS6UdGWGJUYTqliQ7Q",
"Following": "iSicc7LrzWGBgDPL0tM_TQ", "Following": "zx6e-TLzRkeDO_a7p4b3JQ",
"CreateTweet": "bDE2rBtZb3uyrczSZ_pI9g", "CreateTweet": "bDE2rBtZb3uyrczSZ_pI9g",
"DeleteTweet": "VaenaVgh5q5ih7kvyVjgtg", "DeleteTweet": "VaenaVgh5q5ih7kvyVjgtg",
"FavoriteTweet": "lI07N6Otwv1PhnEgXILM7A", "FavoriteTweet": "lI07N6Otwv1PhnEgXILM7A",