Last active
August 5, 2021 15:57
-
-
Save anibalpacheco/4791d7ab20b0317f52a1d2275f572f51 to your computer and use it in GitHub Desktop.
Solution to 429 errors in mercadoago test API
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
# tldr: Retry the request until you got a non-error response. | |
# In my own experience, in less than 40 attempts you can get a non-error response. | |
# For the customer API (Python): | |
response = api_call(...)['response'] | |
response_status = response.get('status') | |
attempts = 0 | |
while response_status == 429 and attempts < max_attempts: | |
response = api_call(...)['response'] | |
response_status = response.get('status') | |
attempts += 1 | |
# For the cards API (Python): | |
response = api_call(...)['response'] | |
response_status = response.get('status') | |
attempts = 0 | |
while response_status in (404, 500) and attempts < max_attempts: | |
response = api_call(...)['response'] | |
response_status = response.get('status') | |
attempts += 1 | |
# For the payments API (Python): | |
response = api_call(...).get('response', {}) | |
response_status = response.get('status') | |
attempts = 0 | |
while response_status in (400, 500) and attempts < max_attempts: | |
response = api_call(...).get('response', {}) | |
response_status = response.get('status') | |
attempts += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment