【问题标题】:Yahoo-Finance module doesn't work anymore? [duplicate]Yahoo-Finance 模块不再工作? [复制]
【发布时间】:2017-06-26 06:14:44
【问题描述】:

我一直在 python 中使用 yahoo 财务模块。在过去的几个月里,我把这个项目搁置了,然后又重新开始了。不幸的是,雅虎财务模块背后似乎没有任何东西了!

我从pypi documents 运行示例代码并没有得到任何回报。

>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')
>>> print yahoo.get_open()
None
>>> print yahoo.get_price()
None
>>> print yahoo.get_trade_datetime()
None

虽然我能够打开 GOOG,但当我尝试访问历史数据时出现错误,并且似乎无法访问任何股票的历史数据。

None
>>> goog = Share('GOOG')
>>> goog.get_open()
'956.83'
>>> print(yahoo.get_open())
None
>>> goog.get_historical('2014-04-25', '2014-04-29')
Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packag
es\yahoo_finance\__init__.py", line 120, in _request
    _, results = response['query']['results'].popitem()
AttributeError: 'NoneType' object has no attribute 'popitem'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packag
es\yahoo_finance\__init__.py", line 123, in _request
    raise YQLQueryError(response['error']['description'])
KeyError: 'error'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packag
es\yahoo_finance\__init__.py", line 342, in get_historical
    result = self._request(query)
  File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packag
es\yahoo_finance\__init__.py", line 125, in _request
    raise YQLResponseMalformedError()
yahoo_finance.YQLResponseMalformedError: Response malformed.
>>>

我尝试使用更新的日期范围运行,但没有运气。该模块似乎根本无法获得历史数据,而几周前它还是可靠的。有什么见解吗?

【问题讨论】:

标签: python yahoo-finance


【解决方案1】:

来自 Ed0906 的回答:https://stackoverflow.com/a/44050039/5766416

雅虎停止了他们的桌面连接 API。您仍然可以通过手机连接到它。因此,您可以避免这种情况的一种方法是将 GET 请求的标头设置为某些移动浏览器。

按照 Ed 的方法获取和设置请求中的 crumb。我使用了它,并验证了它的工作原理。

【讨论】:

  • 我没有直接使用 API 我正在使用 python 模块...
猜你喜欢
  • 1970-01-01
  • 2018-08-11
  • 2017-10-18
  • 1970-01-01
  • 2017-10-22
  • 2021-09-01
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多