Phando / Streamdeck-Stonks

Streamdeck plugin stock ticker to watch your assets (market and crypto)
MIT License
25 stars 4 forks source link

Plugin not receiving data, 401 response #31

Closed rdohms closed 1 year ago

rdohms commented 1 year ago

Plugin button was frozen on the logo, took a look in the debug console and saw this:

Its trying to load this URL for my ticker

And its receiving this error:

Failed to load resource: the server responded with a status of 401 ()

I see the same thing when I try to load the link directly, did something switch to paid/authenticated at yahoo?

rdohms commented 1 year ago

Looks to be related to the same error people are seeing here: joshuaulrich/quantmod#382

I do see this in payload:

{
"finance": {
"result": null,
"error": {
"code": "Unauthorized",
"description": "Invalid Crumb"
}
}
}
Phando commented 1 year ago

Thank you for posting this. I was just about to push some optimizations and bug fixes. It looks like there is a deeper issue now. I will look into this issue in hopes that Yahoo Finance didn't just change their policy or disconnect their service.

You can always test the API directly with calls like this: https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&fields=symbol,marketState,regularMarketPrice,regularMarketChange,regularMarketChangePercent,preMarketPrice,preMarketChange,preMarketChangePercent,postMarketPrice,postMarketChange,postMarketChangePercent&symbols=CRM

jfessard commented 1 year ago

I tried hitting the API directly, looks like I get the same error... I also found reports on reddit and stackoverflow. Maybe a new API is needed :(

$ curl https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&fields=symbol,marketState,regularMarketPrice,regularMarketChange,regularMarketChangePercent,preMarketPrice,preMarketChange,preMarketChangePercent,postMarketPrice,postMarketChange,postMarketChangePercent&symbols=CRM
[1] 18
[2] 19
[3] 20
[4] 21
[2]   Done                    region=US
[3]-  Done                    corsDomain=finance.yahoo.com
$ {"finance":{"result":null,"error":{"code":"Unauthorized","description":"Invalid Cookie"}}}
Phando commented 1 year ago

@jfessard A new API indeed. I really liked the data from Yahoo Finance as the end users weren't required to get an API key. The plugin just worked out of the box. If any of you know of other free and keyless APIs please let me know.

Phando commented 1 year ago

I was also playing with something like this as a fix, but I don't think it will work.

fetch('https://finance.yahoo.com') .then(response => response.text()) .then(data => { const crumb = str.match(/"crumb":"(.*?)"/)[1]; return fetch(https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&fields=regularMarketPrice,regularMarketChange,regularMarketChangePercent,preMarketPrice,preMarketChange,preMarketChangePercent&symbols=AAPL&crumb=${crumb}); }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error));

justinodunn commented 1 year ago

They also have this problem in another repo, I think they found a fix but the code is written in R.

#383

rdohms commented 1 year ago

Much like other places hav reported, it seems to be intermittent. For example, today, it's working just fine.

Phando commented 1 year ago

I am requesting and adding the session ID to the data requests. Hopefully this fix will prevent the error in the future. A fix will be in the next version v1.1.10