import requests
import time


def make_request(method, url, headers=None, data=None, retries=3):
    """ make a request, with the ability to have retries in specific return
    codes
    :param method: HTTP verb method
    :param url:
    :param retries: int, this should be greater or equal than 1
    :return:
    """
    no_retry_status = [404, 401, 403]
    may_retry_status = [408, 500, 502, 503]

    if not retries:
        return requests.request(method=method,
                                url=url,
                                headers=headers,
                                data=data)

    while retries:
        r = requests.request(method=method,
                             url=url,
                             headers=headers,
                             data=data)
        if r.status_code in no_retry_status:
            return r

        elif r.status_code in may_retry_status:
            retries -= 1
            time.sleep(1)

            if retries == 0:
                return r
            continue

        else:
            return r