` headers = { ' user-agent ':' Mozilla/5.0(Windows NT 6.3;Win64x64) AppleWebKit/537.36 (KHTML,像壁虎一样)Chrome/85 . 0 . 4183 . 102 Safari/537.36 ',...'接受-语言':' en-US,en;q=0.9,bn;q=0.8 ','接受编码':' gzip,deflate,br'}
URL = ' https://www . NSE India . com/API/equity-stock?index = fu _ nifty bank ' r = requests . get(URL,headers=headers)。json() Traceback(最近一次调用last): File " ",第1行,在文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ requests \ models . py”,第900行,在JSON return complex JSON . loads(self . text,**kwargs)文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ simple JSON _ init _。py”,第525行,在loads return _ default _ decoder . decode(s)文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ simple JSON \ decoder . py”,第370行,在decode obj,end = self.raw_decode(s)文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ simple JSON \ decoder . py”,第400行,在raw_decode返回self.scan_once(s,idx=_w(s,idx)。end())文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ simple JSON \ scanner . py”,第79行,在scan _ once return _scan_once(string,idx)文件“C:\ program data \ anaconda 3 \ lib \ site-packages \ simple JSON \ scanner . py”,第70行,在_ scan _ once中引发JSONDecodeError(errmsg,string,idx)simple JSON . errors . JSONDecodeError:预期值:第1行第1列(char 0)`
此错误< code > simple json . errors . jsondecodeerror 表示请求无法解码站点的JSON。我看了一下链接,它不是json,它只是返回html-https://www.nseindia.com/api/equity-stock?index=fu_niftybank。一定是api的问题,而不是你的代码。