如何禁用或忽略 Yfinance 套餐的 SSL

问题描述 投票:0回答:1

因为我在办公室的防火墙后面,所以在运行 yFinance 包时出现 SSL 错误,我想在他从 yahoo 提取数据时禁用 SSL。

代码示例:

# Load packages
import yfinance as yf
# Get data
df = yf.download('SPY', start='2000-01-01', end='2024-10-01')
# print
print(df)

错误:

Failed to get ticker 'SPY' reason: HTTPSConnectionPool(host='fc.yahoo.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)')))
[*********************100%***********************]  1 of 1 completed

1 Failed download:
['SPY']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')
Empty DataFrame
Columns: [(Adj Close, SPY), (Close, SPY), (High, SPY), (Low, SPY), (Open, SPY), (Volume, SPY)]
Index: []

有人知道这个问题的解决方案吗?

python ssl yfinance
1个回答
0
投票

查看 Tickers 的 文档

download()
看起来您可以将默认的
requests
会话替换为您自己的会话。我相信像下面这样的东西可能会起作用:

import requests 
import yfinance as yf
    
unsafe_session = requests.session()
unsafe_session.verify = False

# Get data
df = yf.download('SPY', start='2000-01-01', end='2024-10-01', session=unsafe_session)
# print
print(df)
© www.soinside.com 2019 - 2024. All rights reserved.