Skip to content Skip to sidebar Skip to footer

Python3, Requests: How To Merge Cookiejars

I am learning Python and using the Requests Lib. I want to use a CookieJar to store cookies, but I cannot find out how to add a response's Cookies to an existing CookieJar: CookieJ

Solution 1:

Try this way

# Create cookie one
one = requests.cookies.RequestsCookieJar()

# Create cookie two
two = requests.cookies.RequestsCookieJar()

# set some cookie value
one.set("one_key", "one_value")
two.set("two_key", "two_value")

print(one)
<RequestsCookieJar[<Cookie one_key=one_value for />]>

print(two)
<RequestsCookieJar[<Cookie two_key=two_value for />]>

# Now merge    
one.update(two)
<RequestsCookieJar[<Cookie one_key=one_value for />, <Cookie two_key=two_value for />]>

Post a Comment for "Python3, Requests: How To Merge Cookiejars"