Created
March 22, 2021 20:53
-
-
Save johnmastro/0b5a1e776b2857402d6efcae35e6b32e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AirtableClient: | |
# ... | |
def request(self, method, *args, **kwargs): | |
# ... | |
retries = 0 | |
wait = 30 | |
while True: | |
response = self.session.request(method, *args, headers=headers, **kwargs) | |
if response.status_code != 429 or retries == 3: | |
break | |
retries += 1 | |
log.warn( | |
"http 429 response from airtable, retry after wait", | |
retry=retries, | |
wait=wait, | |
) | |
time.sleep(wait) | |
wait = math.ceil(wait * 1.5) | |
response.raise_for_status() | |
time.sleep(1 / self.requests_per_second_limit) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment