Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 206
Mubbashir Ali Avatar asked Oct 26 '25 02:10

Mubbashir Ali


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)
like image 127
Mubbashir Ali Avatar answered Oct 27 '25 16:10

Mubbashir Ali