Forums

Website Whitelisting

kindly add "https://www.nseindia.com/api/option-chain-indices?symbol=BANKNIFTY" to whitelist

As you're using a paid account, you should be able to connect with all internet resources.

But, I am not getting any response, the console is not showing anything.

.

import pandas as pd
import sys
import requests
from bs4 import BeautifulSoup
import re
import os
import datetime
import time
import numpy as np
print('welcome')
from typing import Dict
pd.set_option('display.max_rows', 3000)
pd.set_option('display.max_columns', 500)
pd.set_option('display.float_format', lambda x: '%.3f' % x)
from IPython.display import display


stock_url  = 'https://www.nseindia.com/api/option-chain-indices?symbol=BANKNIFTY'
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'}
response = requests.get(stock_url, headers=headers).json()

print(response)

I am getting response output if I run this in local using the same code.

enter image description here

Is console printing the 'welcome' string?

yes, its printing

When I ran the below command in the console - "import socket; socket.gethostname()", I am getting "blue-liveconsole4" as output.

I doesn't look like it the issue with particular console server being blacklisted; I tried your code locally, and I'm getting response 401. Are you sure you can get a successful response when you run it from outside of PythonAnywhere? 401 may indicate that there's additional authentication required.

yes, I am getting successful response in my local.

I am fetching data from a public domain. No authentication is required for that.

I'm still not able to connect with that endpoint from PythonAnywhere as well -- it's possible that they don't want to be hit from certain IPs, you may contact their support and ask -- there are no constraints on PA side.

how can I cange my Ip ? after changing will that work?

If you're running from a console, you can try a different console. For web apps, you can delete the web app and re-create it. For scheduled tasks, you cannot change the IP and for always on tasks, you can stop and start it. Not all of these are guaranteed to change your IP, but they're quite likely to.