Simple retry loop

Retry on connection errors or 5xx.

import requests
for _ in range(3):
    r = requests.get(url)
    if r.ok: break