Maybe I'm wrong, but I have a POST request:
response = requests.post(full_url, json.dumps(data))
This could potentially be caused by several reasons, some of which are related to data, some of which are temporary failures, which, due to a poorly designed endpoint, may return as the same error (the server does unpredictable things with invalid data). To catch these temporary glitches and let others go through, I thought the best way to do this is to repeat it once, and then continue if the error occurs again. I believe I can do this with a nested try / except, but it seems like bad practice to me (what if I want to try twice before giving up?)
This solution will be:
try: response = requests.post(full_url, json.dumps(data)) except RequestException: try: response = requests.post(full_url, json.dumps(data)) except: continue
Is there a better way to do this? Alternatively, is there a better way to handle potentially erroneous HTTP responses altogether?
source share