1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

[twitter] retry API calls when their response contains errors (#4811)

This commit is contained in:
Mike Fährmann 2023-12-05 15:57:26 +01:00
parent cf5702c843
commit a4e6ea667b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -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