Yahoo-Finance 模块不再工作了? [英] Yahoo-Finance module doesn't work anymore?

查看:36
本文介绍了Yahoo-Finance 模块不再工作了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我运行了 pypi 文档中的示例代码,但没有得到任何回报.

<预><代码>>>>从 yahoo_finance 导入 分享>>>雅虎 = 分享('YHOO')>>>打印 yahoo.get_open()没有任何>>>打印 yahoo.get_price()没有任何>>>打印 yahoo.get_trade_datetime()没有任何

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

无>>>goog = Share('GOOG')>>>goog.get_open()'956.83'>>>打印(雅虎.get_open())没有任何>>>goog.get_historical('2014-04-25', '2014-04-29')回溯(最近一次调用最后一次):文件C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\yahoo_finance\__init__.py",第 120 行,在 _request_, results = response['query']['results'].popitem()AttributeError: 'NoneType' 对象没有属性 'popitem'在处理上述异常的过程中,又发生了一个异常:回溯(最近一次调用最后一次):文件C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\yahoo_finance\__init__.py",第 123 行,在 _request引发 YQLQueryError(response['error']['description'])密钥错误:'错误'在处理上述异常的过程中,又发生了一个异常:回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\yahoo_finance\__init__.py",第 342 行,在 get_historical 中结果 = self._request(query)文件C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\yahoo_finance\__init__.py",第 125 行,在 _request引发 YQLResponseMalformedError()yahoo_finance.YQLResponseMalformedError:响应格式错误.>>>

我试过在最近的日期范围内运行,但没有成功.历史数据似乎根本无法从模块中获得,而在几周前它还是可靠的.有什么见解吗?

解决方案

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

雅虎停止了用于桌面连接的 API.您仍然可以通过手机连接到它.因此,您可以规避此问题的一种方法是将 GET 请求的标头设置为某些移动浏览器.

按照 Ed 的方法获取和设置请求中的面包屑.我使用了它,并验证它有效.

I've been using the yahoo finance module in python. I put the project down for the last couple months and just started it up again. Unfortunately it doesn't seem that there is anything behind the yahoo finance module anymore!

I run the sample code from the pypi documents and get nothing back.

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

Although I was able to open for GOOG I get an error when I try to access historical data, and cannot seem to access historical data for any stock.

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.
>>>

I've tried running with a more recent date range and no luck. Historical data seems to be simply unavailable from the module, where it was dependable just a few weeks ago. Any insights?

解决方案

From Ed0906's answer here: https://stackoverflow.com/a/44050039/5766416

Yahoo discontinued their API for desktop connections. You can still connect to it via your phone. So one way you can circumvent this is by setting the headers of your GET request to some mobile browser.

OR

Follow Ed's method by getting and setting the crumb in your requests. I used it, and verified it works.

这篇关于Yahoo-Finance 模块不再工作了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆