Coder Social home page Coder Social logo

Yahoo - crumb missing about financials-extension HOT 8 OPEN

rossiwa avatar rossiwa commented on September 17, 2024 1
Yahoo - crumb missing

from financials-extension.

Comments (8)

mbacchi avatar mbacchi commented on September 17, 2024

Same:
image

from financials-extension.

szweep avatar szweep commented on September 17, 2024

Looking at a yahoo-XXX.html file in the .financials-extension directory I see that the crumb is 13 characters long. I'm not sure if this varies or is a new format, but changing the regular expression that matches the crumb from 11 characters to 13 solved the issue for me:

diff --git a/src/financials_yahoo.py b/src/financials_yahoo.py
index 4159dec..1533751 100644
--- a/src/financials_yahoo.py
+++ b/src/financials_yahoo.py
@@ -184,7 +184,7 @@ class Yahoo(BaseClient):
                 return 'Yahoo.getRealtime({}, {}) - handleCookiesAndConsent'.format(ticker, datacode)
 
             try:
-                r = r'\bcrumb=([^"]{11})"'
+                r = r'\bcrumb=([^"]{13})"'
                 pattern = re.compile(r)
                 match = pattern.search(text)
                 if match:

from financials-extension.

cmallwitz avatar cmallwitz commented on September 17, 2024

from financials-extension.

szweep avatar szweep commented on September 17, 2024

This is what I see:

data-url="https://query1.finance.yahoo.com/v7/finance/quote?fields=fiftyTwoWeekHigh%2CfiftyTwoWeekLow%2CfromCurrency%2CfromExchange%2CheadSymbolAsString%2ClogoUrl%2ClongName%2CmarketCap%2CmessageBoardId%2CoptionsType%2CregularMarketTime%2CregularMarketChange%2CregularMarketChangePercent%2CregularMarketOpen%2CregularMarketPrice%2CregularMarketSource%2CregularMarketVolume%2CpostMarketTime%2CpostMarketPrice%2CpostMarketChange%2CpostMarketChangePercent%2CpreMarketTime%2CpreMarketPrice%2CpreMarketChange%2CpreMarketChangePercent%2CshortName%2CtoCurrency%2CtoExchange%2CunderlyingExchangeSymbol%2CunderlyingSymbol&formatted=true&imgHeights=50&imgLabels=logoUrl&imgWidths=50&symbols=IBM&lang=en-US&region=US&crumb=yrtV8%2FbGiDQ"

So the "%2F" looks like a urlencoded character, but I'm unsure whether this is decoded before the pattern is matched. All I know is that I was seeing the "no crumb" error before the change and it worked afterwards. :)

from financials-extension.

szweep avatar szweep commented on September 17, 2024

OK, with further testing I see examples with no urlencoded characters and a length of 11, so my "fix" is no longer working

from financials-extension.

szweep avatar szweep commented on September 17, 2024

Something like this allows the matched string to be longer but ensures the crumb is 11 characters after it is decoded:

diff --git a/src/financials_yahoo.py b/src/financials_yahoo.py
index 1533751..502f5f2 100644
--- a/src/financials_yahoo.py
+++ b/src/financials_yahoo.py
@@ -184,11 +184,13 @@ class Yahoo(BaseClient):
                 return 'Yahoo.getRealtime({}, {}) - handleCookiesAndConsent'.format(ticker, datacode)
 
             try:
-                r = r'\bcrumb=([^"]{11})"'
+                r = r'\bcrumb=([^"]{11,17})"'
                 pattern = re.compile(r)
                 match = pattern.search(text)
                 if match:
-                    self.crumb = urllib.parse.unquote(match.group(1))
+                    crumb = urllib.parse.unquote(match.group(1))
+                    if len(crumb) == 11:
+                        self.crumb = crumb
             except BaseException as e:
                 logger.exception("BaseException ticker=%s datacode=%s", ticker, datacode)
                 del self.realtime[ticker]

from financials-extension.

cmallwitz avatar cmallwitz commented on September 17, 2024

from financials-extension.

cmallwitz avatar cmallwitz commented on September 17, 2024

After some feedback from @szweep I have made some more changes to crumb handling. I'm pretty confident this is is improving things, so if anybody wants to have a go try the new release 3.6.2

from financials-extension.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.