You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中yfinance包调用msft.info接口解密失败问题求助

解决yfinance解密Yahoo数据失败的问题

强制更新至yfinance最新开发版

Yahoo近期调整了数据加密机制,旧版本yfinance的解密逻辑已失效,必须安装最新修复版本。在终端执行:

pip install --upgrade git+https://github.com/ranaroussi/yfinance.git@main

若使用conda环境,先激活对应环境后执行上述命令,或替换为:

conda install -c conda-forge yfinance --force-reinstall

清除yfinance本地缓存

Mac系统中yfinance的缓存目录可能留存旧的无效密钥,导致密钥提取失败。终端执行以下命令删除缓存:

rm -rf ~/.cache/yfinance

完成后重启Jupyter Notebook再运行代码。

验证修复效果

重新运行你的测试代码:

import yfinance as yf
msft = yf.Ticker('MSFT')
print(msft.info)

若仍报错,尝试关闭VPN或切换网络环境——网络代理可能干扰Yfinance抓取用于解密的JS文件,导致密钥提取失败。

备选临时方案(更新版本无效时)

若上述方法均无效,可绕过info方法,直接调用其他可用接口获取数据:

import yfinance as yf
msft = yf.Ticker('MSFT')
# 获取财务报表数据
financial_data = msft.financials
# 获取近1个月历史行情
price_history = msft.history(period="1mo")

内容的提问来源于stack exchange,提问作者Grant Weaver

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 06:20:49