-
Notifications
You must be signed in to change notification settings - Fork 142
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
API calls returning 'Invalid Cookie' #203
Comments
I can confirm I have the same issue (macOS 13.4.1, Python 3.9.10 and yahooquery 2.3.1). |
Same here both in Linux and macOS, every ticker returns Invalid Cookie |
Same here too. Yesterday it was fine. However, the day before yesterday, yahooquery was very unstable. Sometimes it returned correct results, sometimes no attributes were returned. The whole yahoo service is becoming unreliable. Any suggestions? |
same result for me |
same, here's the smallest code I have to reproduce
this outputs
Seemed ok till about 8pm UTC |
Looks like it's back, at least using the examples from above. Curious if you're all seeing that now? Pretty disconcerting though nonetheless as it appears they're most likely phasing these APIs out for requests without proper cookies set by the browser. I could come up with a workaround but it would most likely require selenium, which is less than ideal. |
Unfortunately it still doesn't work for me - even same example as above. |
Still not working for me either. I have a long list of queries on various stocks and it returns the "invalid cookie" message to the very first one. |
python 3.7, yahooquery 2.3.1, no browser, windows 11 here. Location: Greece. |
Given code works for @dpguthrie, I think it will be helpful if everyone adds their location to their report. Maybe Yahoo is slowly rolling out across globe. Just edit your post, don't spam the thread. Me: UK, Invalid Cookie, Linux & everything up-to-date |
Same issue since yesterday (but yesterday only 10% of the requests failed) |
Still not working for me too - as before 100% failure since about 8pm yesterday
|
same for me Python 3.9.16 - location austria
I use my account cookie already for requesting other depot data calling yahoo api directly - could I use it for the calls for yahooquery as well as prev mentioned a selenium impl might not be ideal and a bit of an overkill - I read the cookie out of firefox db and just log in from time to time - its valid for a good number of days |
same for me
|
@kajdo So cookie could be cached, but what about the crumb? |
Ya, I'm not super stoked on adding selenium either - if anyone has a better idea for getting the appropriate cookies, I'm all ears. I do think that the library itself should be responsible for setting up the request in a way that makes valid requests, which means obtaining cookies and a crumb without intervention from the user. I guess it could certainly be another argument to the The alternative that I mentioned above is using selenium. I put together a short loom video on what that might look like (it adds a little less than 5 seconds to the Also, I think using the webdriver-manager package abstracts away the requirement of a user having to download chromedriver themselves, which makes it a little bit easier to stomach. |
@ValueRaider I messed around with crumb for the api calls ... also with the cookie itself which i see in the dev console in ff / brave the call i make is basically against "/v7/finance/desktop/portfolio?formatted=true" and i ended up using just
urlparams:
to call the /portfolio endpoint it seems to be fine without crumb @dpguthrie i do agree that its much better if the library handles it .... to reduce the +5sec the lib could cache/persist it in a .env file and load it via dotenv (https://pypi.org/project/python-dotenv/) or something like that .... so it only gets a new token with the browser-simulation if really needed ...... as mentioned the cookie is valid for days - not sure how long but for my script, i think i have to change it once every 2 weeks max don't really have a better suggestion .... messed around a bit, but ended up reading it out from ff cookie db because i'm online on yahoo finance anyway often enough to not redo the tocken manually |
Me since today 13th July: |
It appears that the Yahooquery library attempts to access the Yahoo Finance API using authentication cookies. However, Yahoo Finance has made changes to its API, and it's possible that the authentication cookies are no longer valid or need to be updated. |
We are still in the dark it seems. Sorry I don't have the necessary skills to contribute to the discussion, but I sincerely hope that we will soon have a practical solution accompanied by a comprehensive explanation and we can return to our trading habits. I wish to thank Doug in advance for his superb work and his commitment to yahooquery. |
just encountered this issue. utc+8. From yfinance repo, users are also discussing this issue. Some said that "A1 and the crumb URL parameter" are needed at least for the call. I don't know how to get the crumb and cookie through python without additional libraries or tools. I would be really appreciate if anyone could give me some hints. ps. I notice the 'https://dpguthrie-yahooquery-streamlit-app-eydpjo.streamlit.app/' website still works. I am not sure how can it still work if it is using yahooquery's api? Would anyone mind giving me some hints? I think selenium is the right choice to adopt since yahoo is making it harder and harder for programmatic crawling. Finally, we will reach a point where crawling with a fake browser is the only choice. Thanks a lot for the work! **the request response now changed from 401 to 404. Also, the 'https://dpguthrie-yahooquery-streamlit-app-eydpjo.streamlit.app/' website starts getting 'invalid cookies' respond now. |
If they are rolling out the breaking change regionally, it hit EST / UTC-5 sometime between ~18:00 and ~21:00 UTC-5 I was manually running a job which I halted at 17:40 UTC-5 - upon just resuming to finish the job at 21:00 UTC-5 I now encounter this error. |
I just started seeing this error today as well. |
Is this error unsolvable? |
Same issue (Israel, Python 3.11) |
import yahooquery If you ask history it works perfectly!! But if you ask for price "Invalid Cookie". |
I think this is a very unstable way of getting data. After the try is triggered, you can add the code of yfinance to the exception, so that the data can still be obtained when the exception occurs. This may require code changes, but will not delay daily backtesting. |
@dpguthrie maybe a crazy idea - but what if we could make the login process work with mechanize (https://mechanize.readthedocs.io/en/latest/) ... the benefit would be that no seperate browser is needed and it would run on a vps without desktop environment as well something like: import mechanize
# Create a browser instance
browser = mechanize.Browser()
# Open the login URL
login_url = 'https://login.yahoo.com/?done=https%3A%2F%2Fwww.yahoo.com%2F&add=1'
response = browser.open(login_url)
# Read the HTML response and decode it as a string
html = response.read().decode('utf-8')
# Find the login form with id="login-username-form"
forms = [form for form in browser.forms() if form.attrs.get('id') == 'login-username-form']
if forms:
# Select the first form found
form = forms[0]
# Find the username input field
username_field = form.find_control('username')
if username_field:
# Assign the value to the username input field
username_field.value = 'USERNAME'
# Find the submit button and directly submit the form
submit_button = form.find_control(id='login-signin', type='submit')
if submit_button:
browser.form = form # Set the form explicitly
try:
browser.submit()
# Print the current URL after submitting the form
print("Current URL:", browser.geturl())
except mechanize.HTTPError as e:
print(f"Failed to submit the form: {e.code} {e.msg}")
except mechanize.URLError as e:
print(f"Failed to submit the form: {e.reason}")
else:
print("The submit button was not found in the form.")
else:
print("The username input field was not found in the form.")
else:
print("The form with id='login-username-form' was not found in the HTML.")
# Close the browser
browser.close() just as an example ... it still ends up in |
it's also broken here: |
A temporary (or permanent - not sure yet) alternative:
The available |
Working on a new fix right now that doesn't require selenium. You can test by installing from the |
I did To figure out what's going on I created an interactive selenium session and found that Yahoo! now uses occasional recaptcha challenges before the userid prompt, or before the password prompt. |
Just wanted to say how great it is to see such wide community participation in trying to get a timely stable resolution to all this. A huge thank you to @dpguthrie and all those here who are contributing ideas. |
The link to the streamlit app on https://yahooquery.dpguthrie.com/ is https://share.streamlit.io/app/dpguthrie-yahooquery-streamlit-app-eydpjo/ which is broken: |
@micktg I can update the docs site. The README has been updated with the appropriate URL Go here - https://yahooquery.streamlit.app |
Is there a permanent fix for
I'm trying to avoid swapping it out for an extensive |
@cmjordan42 Ya, I'm trying to work on a solution in #205 . There appears to be some issues though - I've been able to get it to work locally and in the streamlit app but others who have installed it are running into errors. TLDR:
|
Dear all, <ticker_SP500 = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0] When I call "ticker.summary_detail" key, I get the following errors which I did not get before this issue and the 2.3.2 update: < File ~...\yahooquery\base.py:1217 in _construct_data FYI, instead of S&P500, if I read into Nasdaq100 tickers using the following code, everything works fine: <ticker_Nasdaq100 = pd.read_html('https://en.wikipedia.org/wiki/Nasdaq-100')[4] I cannot figure out what is the problem with the S&P500 ticker or symbol list. Thanks a lot! |
= = = = I tried you S&P500 example and get for the Ticker the lists op the S&P500 companies Regarding "ticker.summary_detail" I'm a bit confused . . . maybe you have to write a capital "T" It might be related with the "Invalid cookie" issues????? In general . . . as a non-technician I'm a bit lost how to solve the "Invalid cookie" problem Many thnx in advance |
For those of you who stumble upon the same problem like me with S&P500 tickers, the problem arises from those tickers that include a dot in it: BRK.B and BF.B, particularly the latter. To solve it, needed some help with coding from a friend who deployed a "try" and "except" loop across tickers. If anyone is interested, I can copy the code here. Thanks! |
I'd suggest Stack Exchange for coding help, it's geared towards that whereas this is more for investigating and addressing the issue/bug at hand. I'm not sure what you're trying to do, but it may help to know that "BRK.B" can be queried as "BRK-B" to get that security's data. |
use VPN connect to USA. |
I tried |
@ValueRaider
I get : |
Simplify your code
|
ah, something broke then with the new version: while each on their own work:
because there was a cookie error as well for a while, I thought the two issues were connected. |
I found a "solution" --> if you are not in the US, just try to connect with a VPN from the USA |
python v3.11 from Germany {'AMZN': 'Invalid Cookie'} |
fc.yahoo.com blocked by my adlists. i fixed it!
|
Python 3.9.6
|
Same error here (Italy): stock = Ticker('UCG.MI') Python 3.11.7, Yahooquery 2.3.5 Update: |
@danielegramola same error in version 2.3.7,region:Taiwan |
So, back to square one? I am also getting invalid cookie in my program, which used to work after installing 2.3.2. |
current version is > 2.3.5 (2.3.5 seems to work fine for me) |
I am in Greece, none of the versions seems to be working. I see other Europeans complaining. Is there an update that works in Europe? |
As people have suggested elsewhere, in Europe looks like it's necessary to pass the 'asynchronous' argument to Certainly try that if you haven't already. Works for me. |
It works now. Thank you very much!
|
Describe the bug
API calls returning 'Invalid Cookie'
To Reproduce
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: