Skip to content

Instantly share code, notes, and snippets.

@miguelmontemayor
Last active April 21, 2017 21:21
Show Gist options
  • Save miguelmontemayor/e5dffd81c8c26b6c14c1dd4ffbc30299 to your computer and use it in GitHub Desktop.
Save miguelmontemayor/e5dffd81c8c26b6c14c1dd4ffbc30299 to your computer and use it in GitHub Desktop.
max_attempts = 10
attempts = 0
while attempts < max_attempts:
# Make a request to Clover REST API
response = requests.get(request_url, headers = {"Authorization": "Bearer " + api_token})
# If not rate limited, break out of while loop and continue with the rest of the code
if response.status_code != 429:
break
# If rate limited, wait and try again
time.sleep((2 ** attempts) + random.random())
attempts = attempts + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment