[twitter] retry API calls when their response contains errors (#4811)
This commit is contained in:
@@ -1276,8 +1276,18 @@ class TwitterAPI():
|
|||||||
self.headers["x-csrf-token"] = csrf_token
|
self.headers["x-csrf-token"] = csrf_token
|
||||||
|
|
||||||
if response.status_code < 400:
|
if response.status_code < 400:
|
||||||
# success
|
data = response.json()
|
||||||
return 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:
|
if response.status_code == 429:
|
||||||
# rate limit exceeded
|
# rate limit exceeded
|
||||||
|
|||||||
Reference in New Issue
Block a user