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

Can we just raise HTTPErrors instead of logging them? #2213

Open
mRcSchwering opened this issue Jan 8, 2025 · 2 comments
Open

Can we just raise HTTPErrors instead of logging them? #2213

mRcSchwering opened this issue Jan 8, 2025 · 2 comments

Comments

@mRcSchwering
Copy link

Describe bug

The _fetch method on Quote in scrapers.quote checks a few things and raises error. Just requests.exceptions.HTTPError is not raised. Instead it is caught and an error is logged (see:

utils.get_yf_logger().error(str(e))
)

        try:
            result = self._data.get_raw_json(_QUOTE_SUMMARY_URL_ + f"/{self._symbol}", user_agent_headers=self._data.user_agent_headers, params=params_dict, proxy=proxy)
        except requests.exceptions.HTTPError as e:
            utils.get_yf_logger().error(str(e))
            return None
        return result

I would like to catch this error and handle it when using yfinance. Why not do something like:

        try:
            result = self._data.get_raw_json(_QUOTE_SUMMARY_URL_ + f"/{self._symbol}", user_agent_headers=self._data.user_agent_headers, params=params_dict, proxy=proxy)
        except requests.exceptions.HTTPError as e:
            raise YFException(str(e))
        return result

(Posted it as "Bug" because it seems like an exception should be handled or raised)

Simple code that reproduces your problem

try:
    Ticker("BIG").info()
except Exception as err:
    error = err
print(error)

Debug log

404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/BIG?modules=financialData%2CquoteType%2CdefaultKeyStatistics%2CassetProfile%2CsummaryDetail&corsDomain=finance.yahoo.com&formatted=false&symbol=BIG&crumb=92tlCzJ1hkE
>>> error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'error' is not defined. Did you mean: 'OSError'?

Bad data proof

No response

yfinance version

0.2.51

Python version

No response

Operating system

No response

@ValueRaider
Copy link
Collaborator

The catch was added here 61c4696. The idea is preventing a suddenly-delisted symbol from breaking a users' code.

Ticker.history() has argument raise_errors - maybe this can be promoted to a global setting?

@R5dan
Copy link
Contributor

R5dan commented Jan 9, 2025

Ticker.history() has argument raise_errors - maybe this can be promoted to a global setting?

I could add it to my config pr. Let it be set globally.

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

3 participants