Getting an Assertion Error assert cookie_dict['sameSite'] in ['Strict', 'Lax'] while trying to set cookies for google login in Selenium

Viewed 1179
with Chrome() as driver:
    driver.get(notebooks[0])

    for cookie in pickle.load(open('cookies.pkl', 'rb')):
        driver.add_cookie(cookie)

I dumped the cookies first by logging in manually, but getting this error while setting them.

1 Answers

Found the answer to it!

Found out that google doesn't allow sending 'sameSite' cookie set to 'None'

Since 'sameSite' cookie was set to 'None' when I saved it from site, so sending it set to 'None' was against google's policy, resulting in assertion that it should be 'Strict' or 'Lax'

Here is the code that solved the problem

for cookie in pickle.load(open('cookies.pkl', 'rb')):
    if 'sameSite' in cookie:
        if cookie['sameSite'] == 'None':
            cookie['sameSite'] = 'Strict'
    driver.add_cookie(cookie)
Related