import requests


def getURLChain(targetURL):
    """For the given URL, return the chain of URLs following any redirects
    """
    ok = False
    chain = []
    try:
        r = requests.head(targetURL, allow_redirects=True)
        ok = r.status_code == requests.codes.ok  # pylint: disable=no-member
        if ok:
            for resp in r.history:
                chain.append(resp.url)
    except (requests.exceptions.RequestException, requests.exceptions.ConnectionError,
            requests.exceptions.HTTPError, requests.exceptions.URLRequired,
            requests.exceptions.TooManyRedirects, requests.exceptions.Timeout):
        ok = False
    return (ok, chain)