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

Why is yahoo-finance2 outputting a lot of unwanted text on my Mac Terminal? #702

Open
GA-VI opened this issue Oct 25, 2023 · 7 comments
Open
Labels
bug Something isn't working

Comments

@GA-VI
Copy link

GA-VI commented Oct 25, 2023

Bug Report

Describe the bug

When getting the latest S&P 500 index data using the following node.js code, running on an Apple Mac Terminal:

var quote = await yahooFinance.quote("^GSPC")

I notice that yahoo-finance2 now outputs a lot of text on the Terminal. The text that it outputs is:

Fetching crumb and cookies from https://finance.yahoo.com/quote/AAPL...
fetch https://guce.yahoo.com/consent?brandType=nonEu&gcrumb=LvaAxoM&done=https%3A%2F%2Ffinance.yahoo.com%2Fquote%2FAAPL
fetch https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_4b45750a-1d2e-4a35-8971-0ac4f061bd1c
fetch https://consent.yahoo.com/v2/collectConsent?sessionId=3_cc-session_4b45750a-1d2e-4a35-8971-0ac4f061bd1c
fetch https://guce.yahoo.com/copyConsent?sessionId=3_cc-session_4b45750a-1d2e-4a35-8971-0ac4f061bd1c&lang=en-GB
Fetching crumb and cookies from https://finance.yahoo.com/quote/AAPL?guccounter=1...
Success. Cookie expires on Infinity
New crumb: 4h03r8BxYn3

How can I prevent this text output from appearing on the Terminal?

Minimal Reproduction

const yahooFinance = require('yahoo-finance2').default;
(async () => {
var quote = await yahooFinance.quote("^GSPC");
}) ()

Environment

Using node.js version v21.1.0.
npm version 10.2.0.

Additional Context

@GA-VI GA-VI added the bug Something isn't working label Oct 25, 2023
@z3nful
Copy link
Contributor

z3nful commented Oct 27, 2023

It should only call the cookie code once per library load, as it checks it's cookie jar each call to see if it has already pulled one. Currently the cookie jar is instance specific.

If you are running the library directly in the terminal, you are reloading the library each time making it so it fetches the cookies each time. To avoid this, you would want to set up your quote calls in a way where you keep the library instance running (like in a expressJS or ReactJS app).

@GA-VI
Copy link
Author

GA-VI commented Nov 2, 2023

It should only call the cookie code once per library load, as it checks it's cookie jar each call to see if it has already pulled one. Currently the cookie jar is instance specific.

Thanks for your reply.

Each time I run my node.js app which loads yahoo-finance2 via the line of code: const yahooFinance = require('yahoo-finance2').default; this text is printed out in the Mac's Terminal. In prior versions of yahoo-finance2, this text never appeared. Is there any way to suppress the text?

@z3nful
Copy link
Contributor

z3nful commented Nov 6, 2023

There was the option for custom logging that was integrated recently, you should be able to set that higher than debug to not show those I think (they're all logger.debug()). I haven't tried yet myself though

@GA-VI
Copy link
Author

GA-VI commented Mar 25, 2024

There was the option for custom logging that was integrated recently, you should be able to set that higher than debug to not show those I think (they're all logger.debug()). I haven't tried yet myself though

Thanks very much for that suggestion. Would you be able to give the exact line of code I can enter to try to suppress these unwanted lines of text on the console? I looked at the documentation, but could not work out what code to add.

Much appreciated.

@ozgrozer
Copy link

ozgrozer commented May 3, 2024

There should be a { debug: false } feature. It's just annoying.

@zadjii-msft
Copy link

zadjii-msft commented Jun 19, 2024

FWIW, this worked for me as of 2.11.3:

// See https://github.com/gadicc/node-yahoo-finance2/issues/778
// the error message
// "We expected a redirect to guce.yahoo.com, but got https://finance.yahoo.com/quote"
// _always_ gets written to console.error, instead of the configured logger.error
console.error = () => {};

yahooFinance.setGlobalConfig({
    // Disable all logging
    logger: {
        info: () => {},
        warn: () => {},
        debug: () => {},
        error: () => {}
    }
});

See:

(obviously, disabling console.error entirely is contrived, but I was building a contrived test app at the time so 🤷)

@gadicc
Copy link
Owner

gadicc commented Jun 19, 2024

Thanks for the example, @zadjii-msft, which I think everyone will appreciate.

I've opened an umbrella issue to track future log changes when we get a chance to work on them (won't be soon, unfortunately).

#783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants