selenium.common.exceptions.WebDriverException: Message: invalid argument: missing 'name'

created at 07-17-2021 views: 1

Use selenium to add a cookie prompt error:

Traceback (most recent call last):
  File "I:/Dropbox/python/spider/zhihu/", line 37, in <module>
  File "I:/Dropbox/python/spider/zhihu/", line 31, in loadCookie
  File "D:\software\python35\lib\site-packages\selenium\webdriver\remote\", line 760, in add_cookie
    self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
  File "D:\software\python35\lib\site-packages\selenium\webdriver\remote\", line 308, in execute
  File "D:\software\python35\lib\site-packages\selenium\webdriver\remote\", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: missing 'name'
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.10586 x86_64)
  • cookie_dict: a dictionary object with required keys-"name" and "value"; optional keys-"path", "domain", "secure", "expiry"

It is found that the cookie must require at least two keys: name and value.

browser = webdriver.Chrome()
# Delete the cookie when the connection is first established
# cookie = getCookie()
# print(type(cookie))
# print(cookie)
cookie={"name": "foo", "value": "bar"}

Added cookie successfully

My previous cookie did not have the two keys of name and value, so adding the cookie failed.

Please log in to leave a comment.