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:
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)