when i use the method fnolist() from package nsepython , i am able to get the data as requested. if i try to use the function locally by copying and running the code i am getting 401 saying resource not found
b'<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>Resource not found</title>\n</head>\n<body style="background-color: #e8e8e8;">\n
<div style="font-size: 32px; padding: 50px 25px; text-align: center;">\n Resource not found\n </div>\n</body>\n</html>\n'
import requests
mode ='local'
if(mode=='local'):
def nsefetch(payload):
output = requests.get(payload,headers=headers).json()
return output
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'DNT': '1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
'Sec-Fetch-User': '?1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-Mode': 'navigate',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,hi;q=0.8',
}
def fnolist():
# df = pd.read_csv("https://www1.nseindia.com/content/fo/fo_mktlots.csv")
# return [x.strip(' ') for x in df.drop(df.index[3]).iloc[:,1].to_list()]
positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
nselist=['NIFTY','NIFTYIT','BANKNIFTY']
i=0
for x in range(i, len(positions['data'])):
nselist=nselist+[positions['data'][x]['symbol']]
return nselist
if __name__ == "__main__":
fnolist()
I was running it locally so that i can replace that securities with something else from equity-stockIndices
also, one additional thing i had issues was, when i run the nsepython.fnolist() in jupyter notebook i get the data, but if i run a python file, it gives 401 (resource not found)