import requests


def retry_request(url, http_method, *args, **kwargs):
    """Make a http request and retry 3 times if it fails."""
    assert http_method in ["get", "post", "delete", "patch", "put"]
    MAX_TRIES = 3
    r_func = getattr(requests, http_method)
    tries = 0
    while True:
        resp = r_func(url, *args, **kwargs)
        if resp.status_code != 200 and tries < MAX_TRIES:
            tries += 1
            continue
        break

    return resp