How to fix “invalid argument: invalid 'expiry'” in Selenium when adding cookies to a chromedriver?

后端 未结 4 818
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 10:14

I\'m trying to add cookies to a browser, but getting the following error:

Message: invalid argument: invalid \'expiry\' (Session info: chrome=75.0.3770.90)

T

4条回答
  •  臣服心动
    2020-12-15 10:29

    The problem is that you are trying to add the cookies with a different format than the selenium expects.

    The python selenium api reference says that you have to insert the cookies with a dict like that

    driver.add_cookie({'name' : 'foo', 'value' : 'bar'})
    

    So you have to adapt your loop to use a key,value format

    for key, value in pickle.load(open(r'{0}\{1}_cookie.pkl'.format(settings.COOKIES_PATH, self.tv_username), 'rb')):
        self.browser.add_cookie({'name' : key, 'value' : value})
    

提交回复
热议问题