我对api和python还是很陌生,只知道一点点代码,但是我试图从Td Ameritrade Api提取股票数据。 我已经按照几个youtube视频获取了此代码以及它们的工作方式,但是当我运行它时,出现了一个错误:完整错误在下面。如果有人知道如何解决这个问题,将不胜感激。
endpoint = r"https://api.tdameritrade.com/v1/marketdata/{}/pricehistory".format('GOOG')
payload = {'apikey': apikey,
'periodType': 'day',
'frequencyType' : 'minute',
'frequency' : '1',
'period' : '2',
'needExtendedHourData' : 'true'}
content = requests.get(url = endpoint, params = payload)
print()
data = content.json()
print(data)
JSONDecodeError Traceback (most recent call last)
<ipython-input-102-6604869a0d57> in <module>
10 content = requests.get(url = endpoint, params = payload)
11
---> 12 data = content.json()
13
14 print(data)
c:\users\steve\appdata\local\programs\python\python37\lib\site-packages\requests\models.py in json(self, **kwargs)
888 try:
889 return complexjson.loads(
--> 890 self.content.decode(encoding), **kwargs
891 )
892 except UnicodeDecodeError:
c:\users\steve\appdata\local\programs\python\python37\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
c:\users\steve\appdata\local\programs\python\python37\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
c:\users\steve\appdata\local\programs\python\python37\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 2 column 11 (char 11)