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

后端 未结 4 815
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  Happy的楠姐
    2020-12-15 10:25

    This is caused by an active bug in chromedriver: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3331

    The bug is that chromedriver returns expiry cookies with get_cookies as a double, but does not accept a double for it with add_cookie. Here's the fix:

    for cookie in pickle.load(open('cookies.pkl', 'rb')):
        expiry = cookie.get('expiry', None)
    
        if expiry:
          cookie['expiry'] = int(expiry * 1000)
        browser.add_cookie(cookie)
    

提交回复
热议问题