Skip to content

Instantly share code, notes, and snippets.

@johnmastro
Created March 22, 2021 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmastro/0b5a1e776b2857402d6efcae35e6b32e to your computer and use it in GitHub Desktop.
Save johnmastro/0b5a1e776b2857402d6efcae35e6b32e to your computer and use it in GitHub Desktop.
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