yahoofinance-api icon indicating copy to clipboard operation
yahoofinance-api copied to clipboard

append the crumb to the URL (Fix #206, #209, #211 and #225)

Open gilbertoca opened this issue 2 years ago • 11 comments
trafficstars

append the crumb to the URL Fix #206, #209, #211 and #225

gilbertoca avatar Jun 14 '23 18:06 gilbertoca

Hi @gilbertoca ,

are you sure that this change alone fixes the problem? At least, I had to also change the cookie retrieval mechanism: https://github.com/v3rtumnus/yahoofinance-api/commit/a961b19136383e5c4a951396604bd97c42ccc690

v3rtumnus avatar Jun 27 '23 07:06 v3rtumnus

@v3rtumnus Yes! I have to say I don't know if the API make any locale request, I'm from Brazil, and I have no complex logic on the call:

        for (AtivoCarteira ativo : carteira) {
            Stock stock = null;
            try {
                final String sticker = ativo.getPapel() + ".SA";
                logger.debug("O simbolo no YahooFiance - {}", sticker);
                stock = YahooFinance.get(sticker);
            } catch (IOException ex) {
                logger.debug("Erro GRAVE", ex);
            }
            if (stock != null) {
                ativo.setStockPrice(stock.getQuote().getPrice());
                ativo.setStockDividend(stock.getDividend().getAnnualYieldPercent());
                ativo.setStockPsr(stock.getStats().getPriceSales());
                ativo.setStockPe(stock.getStats().getPe());
            }

gilbertoca avatar Jun 27 '23 11:06 gilbertoca

Ah this could actually explain it because I am from the EU and had problems with the cookie consent banner (maybe this one is not shown when visiting Yahoo outside of EU)

v3rtumnus avatar Jun 27 '23 18:06 v3rtumnus

I am trying to access the historical data and getting this error, I am at Polish Region(EU) too java.io.IOException: Server returned HTTP response code: 401 for URL: https://query1.finance.yahoo.com/v7/finance/quote?symbols=GOOG

vkmguy avatar Jul 15 '23 08:07 vkmguy

still got an error "Server returned HTTP response code: 429 for URL: https://query1.finance.yahoo.com/v1/test/getcrumb"

chungyeong avatar Dec 08 '23 14:12 chungyeong

Just as a side note, by accident I discovered today that with Java 21 I got 404 (or 401, don't remember) but Java 1.8 worked fine. Maybe Java 21 doesn't allow you to override the user agent and Yahoo picks up on that.

code-monkey-101 avatar Dec 08 '23 16:12 code-monkey-101

Hey In addition to changes that were made in this PR, cookie name wasn't accurate, code was looking for B= cookie while it has been changed to A1S=, so I changed it in CrumbManager.java and it worked. No errors, running on Java 17, outside of USA.

image

bnsd55 avatar Apr 25 '24 09:04 bnsd55

Thank you @bnsd55 !

On my side, I was getting this exception

Caused by: java.io.IOException: Server returned HTTP response code: 503 for URL: https://finance.yahoo.com/quote/%5EGSPC/options

gilbertoca avatar Apr 25 '24 11:04 gilbertoca

@sstrickx could you pls approve and merge, we need this release

foxhound91 avatar Jun 18 '24 12:06 foxhound91

@gilbertoca this ain't working, try running this test in your local

public class CrumbManagerTest {

    @Test
    public void testGetCrumb() throws IOException {
        assertNotNull(CrumbManager.getCrumb());
    }

}

foxhound91 avatar Jun 19 '24 15:06 foxhound91

@foxhound91, it is working locally

image

gilbertoca avatar Jun 19 '24 16:06 gilbertoca