python-scraping icon indicating copy to clipboard operation
python-scraping copied to clipboard

Error occurred when running chapter-12/2-seleniumCookies.py

Open 8cold8hot opened this issue 9 years ago • 2 comments

The output of this script is:

[{'expires': 'Sun, 18 Dec 2016 12:53:17 GMT', 'name': '_gat', 'path': '/', 'expiry': 1482065597, 'domain': '.pythonscraping.com', 'httponly': False, 'value': '1', 'secure': False}, {'expires': 'Tue, 18 Dec 2018 12:43:17 GMT', 'name': '_ga', 'path': '/', 'expiry': 1545136997, 'domain': '.pythonscraping.com', 'httponly': False, 'value': 'GA1.2.2049848913.1482064997', 'secure': False}, {'name': 'has_js', 'path': '/', 'domain': 'pythonscraping.com', 'httponly': False, 'value': '1', 'secure': False}]

WebDriverException Traceback (most recent call last) in () 12 driver2.delete_all_cookies() 13 for cookie in savedCookies: ---> 14 driver2.add_cookie(cookie) 15 16 driver2.get("http://pythonscraping.com")

/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py in add_cookie(self, cookie_dict) 669 670 """ --> 671 self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict}) 672 673 # Timeouts

/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params) 234 response = self.command_executor.execute(driver_command, params) 235 if response: --> 236 self.error_handler.check_response(response) 237 response['value'] = self._unwrap_value( 238 response.get('value', None))

/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response) 190 elif exception_class == UnexpectedAlertPresentException and 'alert' in value: 191 raise exception_class(message, screen, stacktrace, value['alert'].get('text')) --> 192 raise exception_class(message, screen, stacktrace) 193 194 def _value_or_default(self, obj, key, default):

WebDriverException: Message: {"errorMessage":"Can only set Cookies for the current domain","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"243","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:58537","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"POST","post":"{"cookie": {"expires": "Sun, 18 Dec 2016 12:53:17 GMT", "name": "_gat", "path": "/", "expiry": 1482065597, "domain": ".pythonscraping.com", "httponly": false, "value": "1", "secure": false}, "sessionId": "94eb85a0-c51f-11e6-badf-39312152c0b6"}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/94eb85a0-c51f-11e6-badf-39312152c0b6/cookie"}} Screenshot: available via screen

How to eliminate this error? Thank you in advance.

8cold8hot avatar Dec 18 '16 12:12 8cold8hot

Here solution http://stackoverflow.com/questions/30292025/selenium-trying-to-log-in-with-cookies-can-only-set-cookies-for-current-doma/39912534#39912534

ohotnikoff avatar Jan 18 '17 20:01 ohotnikoff

Thank you, it works.

8cold8hot avatar Jan 19 '17 07:01 8cold8hot