[Python] yfinance rate limit error when using date variables but not hardcoded dates

Discussão em 'Python' iniciado por Stack, Julho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to fetch daily data from yfinance API, but I'm facing a problem that when I use the date variables I get this error:

    YFRateLimitError('Too Many Requests. Rate limited. Try after a while.')


    but when I hardcode the date it works without any problem.

    This is how I get the date (Not working):

    import pandas as pd
    from datetime import datetime, timedelta

    today = pd.Timestamp.today().normalize()
    today_date = today.strftime('%Y-%m-%d')
    yesterday_date = (today - timedelta(days=1)).strftime('%Y-%m-%d')
    tomorrow_date = (today + pd.Timedelta(days=1)).strftime('%Y-%m-%d')

    print(f"Yesterday: {yesterday_date}") -> # Yesterday: 2025-07-05
    print(f"Today: {today_date}") -> # Today: 2025-07-06
    print(f"Tomorrow: {tomorrow_date}") -> # Tomorrow: 2025-07-07

    print(f"are thay equal? {today_date == "2025-07-06"}") -> # true
    print(f"are thay equal? {yesterday_date == "2025-07-05"}") -> #true
    print(f"are thay equal? {tomorrow_date == "2025-07-07"}") -> # true


    Hardcoded dates (Working):

    stock_data = yf.download(
    tickers=ticker,
    interval="1d",
    start= "2025-07-06",
    end= "2025-07-07",
    progress=False
    )


    yfinance version: 0.2.64 python version:3.13.5

    I tried the Python datetime object and pandas Timestamp to get dates but I got the same error.

    I want to use the date variables instead of hardcoding them because I will make it a cron job in the future.

    Any suggestions or guidance would be greatly appreciated. Thank you

    Continue reading...

Compartilhe esta Página