import requests


def request(url, to_json=False):
    """
        Sends a request to an url and
        makes sure it worked
    """
    response = requests.get(url)
    if not response.ok:
        raise ValueError(
            f"Failed to get a good response when retrieving from {url}. Response: {response.status_code}"
        )
    if not to_json:
        return response.content.decode("utf-8")
    else:
        return response.json()