From a4e6ea667bf2860c72b90afb36ba4750cff98600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 5 Dec 2023 15:57:26 +0100 Subject: [PATCH] [twitter] retry API calls when their response contains errors (#4811) --- gallery_dl/extractor/twitter.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index 56877ede..92c4ce4a 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -1276,8 +1276,18 @@ class TwitterAPI(): self.headers["x-csrf-token"] = csrf_token if response.status_code < 400: - # success - return response.json() + data = response.json() + if not data.get("errors"): + return data # success + + msg = data["errors"][0].get("message") or "Unspecified" + self.extractor.log.debug("internal error: '%s'", msg) + + if self.headers["x-twitter-auth-type"]: + continue # retry + + # fall through to "Login Required" + response.status_code = 404 if response.status_code == 429: # rate limit exceeded