Forums

GET Request Getting Hung Up

Hello!

I am trying to run the following code in my PA virtualenv:

def get_dividend_data(date):
    url = 'https://api.nasdaq.com/api/calendar/dividends'
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0",
        "Accept": "application/json",
    }
    params = {'date': date}
    response = requests.get(url=url, headers=headers, params=params)
    return response.json()

It runs like a charm when I run it locally, but when I run in it on PythonAnywhere it gets hung up on the API call and just stalls forever. Additionally, I have been able to make other similar API calls within my virtualenv so it seems like the issue is with this call specifically.

What do you see in your logs? (link to logs are available on the "Web" page on PythonAnywhere).

Not seeing anything relevant in the logs. However, I am now getting this when returning response.text:

'<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nYou don\'t 
have permission to access "http&#58;&#47;&#47;api&#46;nasdaq&#46;com&#47;api&#47;cal
endar&#47;dividends&#63;" on this server. 
<P>\nReference&#32;&#35;18&#46;c5fa3b17&#46;1675266374&#46;4b5fcce\n</BODY>\n</HTML>\n'

Any way to bypass this? And am I going to have this issue trying to run the code on any hosted environment?

It looks like you're using the same console since you upgraded. Start a new console and try to run the code again.

I exit out of my console and start a new one every time I start a new session. Are you referring to something other than that?

We (our ip addresses) might be blocked by them.