I'm trying to make requests retry if the response status code is not 200, so I wrote this function:
def _get_resource(url, max_retries=0, delay=0):
number_retries = 0
response = requests.get(url)
while response.status_code != 200 and number_retries < max_retries:
time.sleep(delay)
response = requests.get(url)
number_retries += 1
response.raise_for_status()
return response.content
Any suggestions to improve it?
self
. It's undefined in this sample code.