Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 Client Error (only on certain tickers - which are still active/not delisted) #1957

Open
csirick2020 opened this issue Jun 7, 2024 · 2 comments

Comments

@csirick2020
Copy link

Describe bug

I have a program that cycles through a list of all the S&P500 companies to check the 'upgrades_downgrades' attribute of each one (with a for loop). It gets the tickers from a well maintained Wikipedia page (scraping with BeautifulSoup4). All the tickers are up to date (I have personally checked), are able to be found on the Yahoo Finance website and are not delisted. All the tickers are in the correct format, as I apply that after they are scraped. While most of the tickers work once the program starts iterating through them, there are a few that have been raising this 404 Client Error since maybe about a month or two ago. Again, the tickers are perfectly fine and the implementation is correct (this is evident in the fact that most of the 503 tickers get a normal response during the iteration). I will provide the full 404 Client Error I receive on some of the symbols in the debug log section.

Simple code that reproduces your problem

The simplest way to reproduce the problem is by putting a couple of the tickers I know are "bad" into a list with a few good ones and making the same type of call on them:

import datetime
import yfinance as yf

error_date = datetime.date(2024, 6, 6)
list_with_some_bad_tickers = ['COF', 'CRL', 'COO', 'FANG', 'LIN', 'LULU']

tickers_data = yf.Tickers(' '.join(list_with_some_bad_tickers))

for symbol in list_with_some_bad_tickers:
    try:
        ticker = tickers_data.tickers[symbol]
        actions = ticker.upgrades_downgrades
        actions_on_error_date = actions[actions.index.date == error_date]
        # Do not print empty DataFrames (for tickers without analyst activity)
        if not actions_on_error_date.empty:
            # Filter the DataFrame based on multiple conditions
            filtered_actions = actions_on_error_date[(actions_on_error_date['Action'].isin(['up', 'init'])) &
                                                    (actions_on_error_date['ToGrade'].isin(['Buy', 'Outperform', 'Overweight']))]
            if not filtered_actions.empty:
                # Print the filtered DataFrame
                print(f"Analyst action(s) for {symbol} on {error_date}:")
                print(filtered_actions)
                print()
    except Exception as e:
        print(f"General error fetching data for {symbol}: {e}")
        print()

Debug log

404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/COO?modules=upgradeDowngradeHistory&corsDomain=finance.yahoo.com&formatted=false&symbol=COO&crumb=jroCz7O300G

404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/LIN?modules=upgradeDowngradeHistory&corsDomain=finance.yahoo.com&formatted=false&symbol=LIN&crumb=jroCz7O300G

Note: When running the code, the 'General error fetching data for {symbol}: 'RangeIndex' object has no attribute 'date'' that is also raised in these two instances is avoidable, and I don't think it has to do with the 404 Client Error. I did not want to make my code snippet unnecessarily long, but I do avoid that error by using pd.to_datetime() in each iteration. It has no bearing on the 404 Client Error, for which I have tried everything I know how to do and still can't catch or avoid it!

**My apologies for not being more familiar with the logging/debugging process. I've been stuck on this bug for a while today and don't have the bandwidth to figure out the proper way to document this Debug log right now.

Bad data proof

I believe this would be considered the 'bad data':

404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/COO?modules=upgradeDowngradeHistory&corsDomain=finance.yahoo.com&formatted=false&symbol=COO&crumb=jroCz7O300G

404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/LIN?modules=upgradeDowngradeHistory&corsDomain=finance.yahoo.com&formatted=false&symbol=LIN&crumb=jroCz7O300G

yfinance version

yfinance 0.2.40

Python version

3.10.12

Operating system

LinuxLite (Ubuntu)

@ValueRaider
Copy link
Collaborator

Looks like spam - spam less? #1513

@csirick2020
Copy link
Author

Looks like spam - spam less? #1513

I guess it's possible, but it's strange that it just started happening in the last 2 or 3 months. I may have updated my yfinance version in that time, but I can't remember for sure. Anyway, thanks for the advice.

As a side note, when I added error handling to skip past these "misfires", the program will complete it's full cycle through all 503 tickers. It's just a few of them that pull this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants