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

Unauthorized error when using .historical() #349

Closed
maxbauer opened this issue Dec 4, 2021 · 5 comments
Closed

Unauthorized error when using .historical() #349

maxbauer opened this issue Dec 4, 2021 · 5 comments

Comments

@maxbauer
Copy link

maxbauer commented Dec 4, 2021

Bug Report

Describe the bug

Sometimes when using the function for retreiving the history I get an 401 error that I'm not authorized. The same error appears when using thr browser.

Minimal Reproduction

const query = "TSLA";
const queryOptions = { period1: "2021-01-01" };
yahooFinance.historical(query, queryOptions).then((history) => {
  console.log(history);
});

Result:

https://query1.finance.yahoo.com/v7/finance/download/TSLA?interval=1d&events=history&includeAdjustedClose=true&period1=0&period2=1638637015
HTTPError: Unauthorized
    at Object.<anonymous> (/Users/.../node_modules/yahoo-finance2/dist/cjs/src/lib/yahooFinanceFetch.js:74:27)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/.../node_modules/yahoo-finance2/dist/cjs/src/lib/yahooFinanceFetch.js:5:58)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 401
}

Environment

Browser or Node: both
Node version (if applicable): 16.13.0
Browser verion (if applicable): Firefox 94

Additional Context

@maxbauer maxbauer added the bug Something isn't working label Dec 4, 2021
@gadicc
Copy link
Owner

gadicc commented Dec 22, 2021

Hey @maxbauer , thanks for your patience.

Unfortunately as we know from experience, Yahoo's servers aren't always so reliable, and these occasional errors happen sometimes (as you saw, in the browser too).

I suggest to try { } catch (e) { } the yahooFinance call and handle errors appropriately. Maybe in the future we could add a feature automatically retry for these kind of errors, it's not a bad idea, but I don't see any of us having the time to work on something like that for a while, unfortunately.

@dtslvr
Copy link
Collaborator

dtslvr commented Sep 7, 2024

This problem is present again since a few hours.

@gadicc
Copy link
Owner

gadicc commented Sep 7, 2024

Mmm, on the Yahoo page for this, e.g. https://finance.yahoo.com/quote/TSLA/history/, I'm pretty sure there used to be a "download" link that would let us retrieve this data as CSV. I don't see that link anymore. Maybe it still appears if you're logged in? I didn't try as I don't have a Yahoo account.

In any event, all the data on the page itself (vs from a "download" link), seems to come from the chart API now. So, I guess our options are:

  1. See if this is temporary and will fix itself again
  2. See if it's possible if you're logged in, adapt the library to support Yahoo credentials
  3. Probably best option, move over to the chart API (although, it would be nice if we adapted historical() to do this for the user with no code changes - I think we should do that but I can't commit to a time yet, maybe someone else will have a chance to do a PR before I get it).

Reopening the issue for now...

@gadicc gadicc reopened this Sep 7, 2024
@gadicc
Copy link
Owner

gadicc commented Sep 7, 2024

@gadicc
Copy link
Owner

gadicc commented Sep 7, 2024

Actually, let's track this in #795 which is more easily discoverable as a recent issue.

@gadicc gadicc closed this as completed Sep 7, 2024
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