雅虎财经模块不再有效了吗?

时间:2017-06-26 06:14:44

标签: python yahoo-finance

我一直在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.
>>>

我尝试使用更新的日期范围并且没有运气。历史数据似乎从模块中看不到,几周前它就是可靠的。任何见解?

1 个答案:

答案 0 :(得分:1)

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

雅虎停止使用其桌面连接API。您仍然可以通过手机连接到它。因此,您可以通过将GET请求的标头设置为某个移动浏览器来解决此问题。

OR

按照Ed的方法获取并设置请求中的crumb。我用它,并验证它有效。