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

Error Code 401 #226

Open
ahmzd21 opened this issue May 21, 2024 · 6 comments
Open

Error Code 401 #226

ahmzd21 opened this issue May 21, 2024 · 6 comments

Comments

@ahmzd21
Copy link

ahmzd21 commented May 21, 2024

Output:
SLF4J(I): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider]
[main] INFO yahoofinance.quotes.query1v7.QuotesRequest - Sending request: https://query1.finance.yahoo.com/v7/finance/quote?symbols=INTC
Error retrieving stock data: Server returned HTTP response code: 401 for URL: https://query1.finance.yahoo.com/v7/finance/quote?symbols=INTC

I was just running a simple code given below:

import yahoofinance.Stock;
import yahoofinance.YahooFinance;
import java.io.IOException;
import java.math.BigDecimal;

public class StockMarket {
public static void main(String[] args) {
try {
Stock stock = YahooFinance.get("INTC");

          BigDecimal price = stock.getQuote().getPrice();
          BigDecimal change = stock.getQuote().getChangeInPercent();
          BigDecimal peg = stock.getStats().getPeg();
          BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

          stock.print();
      } catch (IOException e) {
          System.out.println("Error retrieving stock data: " + e.getMessage());
      }
  }

}

@ahmzd21
Copy link
Author

ahmzd21 commented May 21, 2024

Anyone knows how to fix this?

@ahmzd21 ahmzd21 closed this as completed May 21, 2024
@ahmzd21 ahmzd21 reopened this May 21, 2024
@ferchoman09
Copy link

I'm having the same problem.
It seems Yahoo API is not open anymore :(

@code-monkey-101
Copy link

I'm having the same problem. It seems Yahoo API is not open anymore :(

I'm afraid, it seems you are right.

The response I am getting is this
image

You also can't download the data from the website anymore, not even when you are logged in.
image

It seems you need to pay $40 per month now.
image

Could scrape the data from the webpage, but that's fragile.

@zytan89
Copy link

zytan89 commented Sep 7, 2024

Such a bad news. Does it mean if i need to purchase minimum Gold plan only we can get the token to access the yahoo finance API now? Is there an easy way to make it work with the current java API if we choose to subscribe the Gold plan?

@ProgramComputer
Copy link

I added a LiveTest to this API in my PR #227. All of the previous tests were mocked. Take a look at the OnlineRequestTest class and feel free to add tests. getStats() seems to work. Historical Prices have the 401.

@vw98075
Copy link

vw98075 commented Nov 6, 2024

To my understanding, now you need to have a crumb query parameter and possiblely cookie in the header for every API calls to prevent the 401 error. The source code has some code about crumb. Not sure why the 401 error still occurs. Once getting over this issue, the data is still accessible.

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

6 participants