[Python] CERTIFICATE_VERIFY_FAILED failure while trying to fetch data from YFinance API

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have been using this script to fetch minute data from yfinance, which has been working fine until today. Can someone seem to assist me with what may be the issue?

    import yfinance as yf
    import pandas as pd


    def fetch_last_10_days(symbol: str):
    try:

    stock_data = yf.download(symbol, period="7d", interval="1m")

    if stock_data.empty:
    raise ValueError(f"Failed to fetch data for {symbol}. The data is empty.")

    print(f"Last 10 days of data for {symbol}:")
    print(stock_data)

    return stock_data

    except ValueError as ve:
    print(f"ValueError: {ve}")
    except Exception as e:
    print(f"An unexpected error occurred: {e}")

    return None


    symbol = 'MSFT'
    data = fetch_last_10_days(symbol)

    if data is not None:
    data.to_csv('sample.csv')
    else:
    print("No data to save.")


    I have tried re-installing the certificates and YFinance library but nothing works. this is what i see on the console:


    1 Failed download:
    ['MSFT']: SSLError(MaxRetryError("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 (_ssl.c:997)')))"))
    ValueError: Failed to fetch data for MSFT. The data is empty.
    No data to save.
    ​

    Continue reading...

Compartilhe esta Página