is there a way to skip a url json file when i don’t have access or there’s no information available

You can check the status code and decide what to do in each case. For example:

def data(ticker):
    url = "https://eodhistoricaldata.com/api/fundamentals/{ticker}.LSE?api_token".format(ticker=ticker)

    with requests.get(url, verify=True) as response:
        if response.status_code == 401: 
            print("Not authorized")
        elif response.status_code == 404:
            print("Not found")
        else:
            data = response.json()
            # your logic

You can explore the response object and use it to define more fine grained behaviour (for example: use the reason attribute or print the content of the response).

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top