The pattern I use retries a limited number of times, sleeping for a short, exponentially increasing time interval between each attempt, and finally raising the last-seen exception after repeated failure:
def wrappedRequest( self, uri, args ):
lastException = None
interval = 1.0
for _ in range(3):
try:
result = requests.post(uri, args)
return result
except Exception as e:
lastException = e
time.sleep(interval)
interval *= 2.0
raise lastException
(I actually specifically check for HTTPError, URLError, IOError, and BadStatusLine exceptions rather than the broad net of Exception.)