-
Notifications
You must be signed in to change notification settings - Fork 147
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
Message: invalid cookie domain: Cookie 'domain' mismatch #56
Comments
Hi @m1ch4elx can you post example code that's causing this error? |
|
|
It goes wrong when trying to add cookie to google.com.ec even when webdriver on this page |
Can you tell me a little bit more about what you're trying to accomplish? It seems you want to load some cookies so that you can scrape data out of Gmail? When |
It's just example of cookies, but mail.google.com is redirecting to account.google.com too. The main problem is webdriver trying to apply cookies to google.com.es, cuz of ensure_add_cookies it goes to that page and after that giving domain mismatch error |
And even with mail.google.com it's not working too, cuz when ensure_add_cookies trying to get to mail.google.com it redirects to accounts.google.com and domain mismatch shows |
All The above situation is exactly what the |
Ok, will try it now and get u know |
Same InvalidCookieDomainException happening here. And the driver loads the page unauthenticated |
Hey all, I'm wanting to dig back into this issue, but need a clear and complete example of steps to reproduce. @m1ch4elx your code is the closest to that, but it references a cookies file and I'd need to know how you created that so I can try to make a similar one. |
It's just a simple file with cookies in netscape, Firefox has extension called cookie quick manager that can save cookies in that format |
So you log into Google account manually in Firefox, save the cookies off, and then you want to use requestium to automate interacting with your gmail, am I tracking that right? |
Well, I can say yes, I guess |
I just published a new version that is a bit more robust in its loading of cookies, but ultimately the issue here wasn't Here's code I tested that worked with the latest version: # Only include cookies relevant to the google domain
lastcooks = [c for c in lastcooks if 'google.com' in c['domain']]
# Sort by domain (effectively ensuring the google.com cookies are loaded ahead of mail.google.com)
lastcooks.sort(key=lambda c: c['domain'])
# A handful of cookies still don't load, so make sure to keep going in those cases
for cook in lastcooks:
try:
s.driver.ensure_add_cookie(cook, override_domain='google.com') # Note the domain override here
except Exception as error:
pass
url = 'https://mail.google.com'
s.driver.get(url) @m1ch4elx give this a try and let me know how it goes for you. |
Okay, I'll try it |
I saw similar behavior until I played around with 1) which cookies I tried to load, and 2) the order that I loaded them in. Do some experimentation. |
Okay, thanks anyway |
Hey @m1ch4elx I realize in re-reading my previous post I may have come across as dismissive. I apologize for that. It's just that there isn't much more that What I can say is that when I exported all my cookies using the Firefox plugin you described, then filtered the list by ones whose domain contained With some persistence and trial and error I bet you can figure out what works for your situation also. But for now I'm closing this ticket. |
Traceback (most recent call last):
File "e:\moi soft\4ej\check3.py", line 82, in
s.driver.ensure_add_cookie(cook, override_domain='')
File "C:\Users\Micha\AppData\Local\Programs\Python\Python310\lib\site-packages\requestium\requestium.py", line 279, in ensure_add_cookie
self.add_cookie(cookie)
File "C:\Users\Micha\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 894, in add_cookie
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
File "C:\Users\Micha\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Micha\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidCookieDomainException: Message: invalid cookie domain: Cookie 'domain' mismatch
(Session info: chrome=103.0.5060.114)
webdriver is on the correct domain but can't add cookie :(
The text was updated successfully, but these errors were encountered: