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

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

gilbertoca
Copy link

@gilbertoca gilbertoca commented Jun 14, 2023

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

@gilbertoca gilbertoca changed the title append the crumb to the URL append the crumb to the URL (Fix #206 and #209) Jun 14, 2023
@v3rtumnus
Copy link

Hi @gilbertoca ,

are you sure that this change alone fixes the problem? At least, I had to also change the cookie retrieval mechanism: v3rtumnus@a961b19

@gilbertoca
Copy link
Author

gilbertoca commented Jun 27, 2023

@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());
            }

@v3rtumnus
Copy link

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)

@vkmguy
Copy link

vkmguy commented Jul 15, 2023

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

@gilbertoca gilbertoca changed the title append the crumb to the URL (Fix #206 and #209) append the crumb to the URL (Fix #206, #209 and #211) Aug 1, 2023
@chungyeong
Copy link

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

@code-monkey-101
Copy link

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.

@bnsd55
Copy link

bnsd55 commented Apr 25, 2024

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

Copy link

@bnsd55 bnsd55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change B=.* in line 56 to A1S=.*, that worked for me.

@gilbertoca
Copy link
Author

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 gilbertoca changed the title append the crumb to the URL (Fix #206, #209 and #211) append the crumb to the URL (Fix #206, #209, #211 and #225) Apr 25, 2024
@foxhound91
Copy link

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

@foxhound91
Copy link

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

public class CrumbManagerTest {

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

}

@gilbertoca
Copy link
Author

gilbertoca commented Jun 19, 2024

@foxhound91, it is working locally

image

add simply tests to CrumbManager and QuoteRequestTest
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

Successfully merging this pull request may close these issues.

Intermittent HTTP 401 returned from Yahoo API
7 participants