[twitter] improve and fix retry after hitting rate limit

- replace recursive call with infinite loop
- fix function arguments for recursive call
This commit is contained in:
Mike Fährmann
2021-01-19 23:15:57 +01:00
parent 89a2bcbb2d
commit 069b113cbf

View File

@@ -617,6 +617,8 @@ class TwitterAPI():
def _call(self, endpoint, params, root=None, method="GET"):
if root is None:
root = self.root
while True:
response = self.extractor.request(
root + endpoint, method=method, params=params,
headers=self.headers, fatal=None)
@@ -630,8 +632,9 @@ class TwitterAPI():
return response.json()
if response.status_code == 429:
until = response.headers.get("x-rate-limit-reset")
self.extractor.wait(until=until, seconds=(None if until else 60))
return self._call(endpoint, params, method)
seconds = None if until else 60
self.extractor.wait(until=until, seconds=seconds)
continue
try:
msg = ", ".join(