为什么这个cookie没有效?

时间:2017-02-17 16:24:40

标签: python selenium cookies

这是cookie:

{'secure': False, 'domain': '.dashnet.org', 'httpOnly': True, 'path': '/', 'name': '__cfduid', 'expiry': None, 'value': 'd0c8a701ccb379dc7ac094575c111d6051487290749'}

当尝试使用Selenium模块将其添加到Firefox时,我收到以下错误:

Traceback (most recent call last):
  File "<pyshell#34>", line 1, in <module>
    browser.add_cookie(cookies[0])
  File "C:\Program Files\Python35\lib\site-packages\selenium-3.0.2-py3.5.egg\selenium\webdriver\remote\webdriver.py", line 671, in add_cookie
    self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
  File "C:\Program Files\Python35\lib\site-packages\selenium-3.0.2-py3.5.egg\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python35\lib\site-packages\selenium-3.0.2-py3.5.egg\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: InvalidCookieDomainError is not defined

那么,这个cookie有什么问题?

1 个答案:

答案 0 :(得分:0)

引自https://stackoverflow.com/a/30676300/2158288

&#34; cookie域不应该有一个前导点,如.foo.com - 只需使用foo.com&#34;

也许这就是问题所在。