Last active
April 21, 2017 21:21
-
-
Save miguelmontemayor/e5dffd81c8c26b6c14c1dd4ffbc30299 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
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