我相信问题出在 Requests 库(在 yfinance 中使用)。该错误指示不受信任的 SSL 证书。有一种方法可以通过在请求中设置“verify=False”来跳过 SSL 证书的验证。在这里找到更多信息:Python Requests throwing SSLError
当我查看 yfinance .py 文件时,我发现如下代码行:
r = _requests.get(url=url, proxies=proxy).json()
您可能需要修改这些行以包含 'verify=False' 语句,使其看起来像这样:request.get(url=url, proxies=proxy, verify=False).json()
我不完全确定使用代理时是否允许“验证 = 假”。您可以尝试将其添加到 .py 文件中的请求行中,看看是否可以解决问题。
对于它的价值,我尝试使用约 500 个股票代码(S&P500 列表)运行它,但无法重现此错误。如果您发布您正在使用的 800 股票代码列表,我可以尝试一下。
我的输出:
MMM ABT ABBV ABMD ACN ATVI ADBE AMD AAP AES AFL A APD AKAM ALK ALB ARE ALXN ALGN ALLE AGN ADS LNT ALL GOOGL GOOG MO AMZN AMCR AEE AAL AEP AXP AIG AMT AWK AMP ABC AME AMGN APH ADI ANSS ANTM AON AOS APA AIV AAPL AMAT APTV ADM ARNC ANET AJG AIZ ATO T ADSK ADP AZO AVB AVY BKR BLL BAC BK BAX BDX BRK.B BBY BIIB BLK BA BKNG BWA BXP BSX BMY AVGO BR BF.B CHRW COG CDNS CPB COF CPRI CAH KMX CCL CAT CBOE CBRE CDW CE CNC CNP CTL CERN CF SCHW CHTR CVX CMG CB CHD CI XEC CINF CTAS CSCO C CFG CTXS CLX CME CMS KO CTSH CL CMCSA CMA CAG CXO COP ED STZ COO CPRT GLW CTVA COST COTY CCI CSX CMI CVS DHI DHR DRI DVA DE DAL XRAY DVN FANG DLR DFS DISCA DISCK DISH DG DLTR D DOV DOW DTE DUK DRE DD DXC ETFC EMN ETN EBAY ECL EIX EW EA EMR ETR EOG EFX EQIX EQR ESS EL EVRG ES RE EXC EXPE EXPD EXR XOM FFIV FB FAST FRT FDX FIS FITB FE FRC FISV FLT FLIR FLS FMC F FTNT FTV FBHS FOXA FOX BEN FCX GPS GRMN IT GD GE GIS GM GPC GILD GL GPN GS GWW HRB HAL HBI HOG HIG HAS HCA PEAK HP HSIC HSY HES HPE HLT HFC HOLX HD HON HRL HST HPQ HUM HBAN HII IEX IDXX INFO ITW ILMN IR INTC ICE IBM INCY IP IPG IFF INTU ISRG IVZ IPGP IQV IRM JKHY J JBHT SJM JNJ JCI JPM JNPR KSU K KEY KEYS KMB KIM KMI KLAC KSS KHC KR LB LHX LH LRCX LW LVS LEG LDOS LEN LLY LNC LIN LYV LKQ LMT L LOW LYB MTB M MRO MPC MKTX MAR MMC MLM MAS MA MKC MXIM MCD MCK MDT MRK MET MTD MGM MCHP MU MSFT MAA MHK TAP MDLZ MNST MCO MS MOS MSI MSCI MYL NDAQ NOV NTAP NFLX NWL NEM NWSA NWS NEE NLSN NKE NI NBL JWN NSC NTRS NOC NLOK NCLH NRG NUE NVDA NVR ORLY OXY ODFL OMC OKE ORCL PCAR PKG PH PAYX PAYC PYPL PNR PBCT PEP PKI PRGO PFE PM PSX PNW PXD PNC PPG PPL PFG PG PGR PLD PRU PEG PSA PHM PVH QRVO PWR QCOM DGX RL RJF RTN O REG REGN RF RSG RMD RHI ROK ROL ROP ROST RCL SPGI CRM SBAC SLB STX SEE SRE NOW SHW SPG SWKS SLG SNA SO LUV SWK SBUX STT STE SYK SIVB SYF SNPS SYY TMUS TROW TTWO TPR TGT TEL FTI TFX TXN TXT TMO TIF TJX TSCO TDG TRV TFC TWTR TSN UDR ULTA USB UAA UA UNP UAL UNH UPS URI UTX UHS UNM VFC VLO VAR VTR VRSN VRSK VZ VRTX VIAC V VNO VMC WRB WAB WMT WBA DIS WM WAT WEC WFC WELL WDC WU WRK WY WHR WMB WLTW WYNN XEL XRX XLNX XYL YUM ZBRA ZBH ZION ZTS
[*********************100%***********************] 505 of 505 completed
5 Failed downloads:
- BF.B: No data found for this date range, symbol may be delisted
- AGN: No data found for this date range, symbol may be delisted
- RTN: No data found for this date range, symbol may be delisted
- BRK.B: No data found, symbol may be delisted
- UTX: No data found for this date range, symbol may be delisted
Adj Close ... Volume
A AAL AAP AAPL ABBV ... YUM ZBH ZBRA ZION ZTS
Date ...
2020-05-28 86.690002 10.98 138.440002 318.25 90.029999 ... NaN 943129 328467 3191223 2277508
2020-05-28 86.690002 10.98 138.440002 318.25 90.029999 ... 4006148.0 943129 328467 3191223 2277508
[2 rows x 3030 columns]
>>>