我使用这个程序来获取 json 数据,https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY
但从今天早上开始它在返回时不起作用<Response [401]>。不过,该链接在 chrome 上加载良好。有没有办法在不使用硒的情况下解决这个问题?
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)
Run Code Online (Sandbox Code Playgroud)