0

I want to raise an error in my code if the status code of a request response is 429, which error should I use?

Exception feels too broad and ValueError doesn't seem right at all.

Does requests have errors built-in I can use?

Or are there standard ways of handling things like this that I am not aware of?

Pseudo-code example

import requests

response = requests.request('GET', url)

if response.status_code == 200:
    continue
elif response.status_code == 429:
    raise Exception('''You made too many requests, please wait a 
                       minute and then try again''')
codeananda
  • 939
  • 1
  • 10
  • 16
  • 1
    https://docs.python-requests.org/en/latest/api/#requests.Response.raise_for_status? – jonrsharpe Nov 05 '21 at 08:27
  • 1
    You might also find this thread helpful: https://stackoverflow.com/questions/22786068/how-to-avoid-http-error-429-too-many-requests-python – Mujeeb N. Nov 05 '21 at 08:28

0 Answers0