I have some code to check the API response status, when it is correct, it wil return the reponse.json() from that API. However I want to expand this with a retry command in terms if there is a disconnect between the client and server and eventually a break with the 404 code because now currently I am just redoing the same function.
def API_status_report(url: str):
response = requests.get(url)
if response.status_code == 200:
return response.json()
elif response.status_code == 204:
return response.json()
elif response.status_code == 404:
print("Not Found: retrying")
API_status_report(url)
I am currently looking in the retry module, and I still cannot get my heads arround it, because it is kind of confusing. Can anyone help me on this?