Skip to content

Instantly share code, notes, and snippets.

@anibalpacheco
Last active August 5, 2021 15:57
Show Gist options
  • Save anibalpacheco/4791d7ab20b0317f52a1d2275f572f51 to your computer and use it in GitHub Desktop.
Save anibalpacheco/4791d7ab20b0317f52a1d2275f572f51 to your computer and use it in GitHub Desktop.
Solution to 429 errors in mercadoago test API
# 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