我使用这个程序从
https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY
获取json数据,但自从今天早上起它就无法工作了,因为它返回<Response [401]>
。不过这个链接在Chrome中可以正常加载。有没有办法在不使用Selenium的情况下解决这个问题?import json
import requests
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
'like Gecko) '
'Chrome/80.0.3987.149 Safari/537.36',
'accept-language': 'en,gu;q=0.9,hi;q=0.8', 'accept-encoding': 'gzip, deflate, br'}
res = requests.get("https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY", headers=headers)
print(res)