Reputation: 51
I am trying to copy cookies from a webdriver object to requests, as can be seen in the code below. I get this error message in the last statement of the script.
TypeError: cannot convert dictionary update sequence element #0 to a sequence
import requests
import cookielib
from selenium import webdriver
import urllib
driver = webdriver.Chrome()
driver.get("http://www.google.com/")
cj = cookielib.CookieJar()
#iterate the drive Cookies
for c in driver.get_cookies():
print "%s -> %s" % (c['name'], c['value'])
ck = cookielib.Cookie(name=c['name'], value=urllib.unquote(c['value']), domain=c['domain'], \
path=c['path'], \
secure=c['secure'], rest={'HttpOnly': c['http_only']}, \
version =0, port=None,port_specified=False, \
domain_specified=False,domain_initial_dot=False, \
path_specified=True, expires=None, discard=True, \
comment=None, comment_url=None, rfc2109=False)
print ck
cj.set_cookie(ck)
rsp = requests.get('http://www.cisco.com/', cookies=cj)
Why do I get this error, and how can I fix it?
Upvotes: 2
Views: 1188
Reputation: 3272
What version of requests are you using? There have been significant changes to the way requests handles cookies in the last few releases.
For me, your code runs without generating an exception using requests 0.14.0 (the most recent release at the time of writing).
Upvotes: 1