By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

http request with cookie sending

P: n/a
Hi,

I want to send a cookie on some http request (with urllib2),
so I created a Cookie but I cant associate it with CookieJar object.

for example:

import Cookie
import cookielib, urllib2

C = Cookie.SimpleCookie()
C["a"] = "b"

cj = cookielib.CookieJar()
cj.set_cookie(C)

in the last line I got:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\lib\cookielib.py", line 1593, in set_cookie
if cookie.domain not in c: c[cookie.domain] = {}
AttributeError: 'SimpleCookie' object has no attribute 'domain'

why?
maybe.. there is any code example for sending cookie with some http
request operation?

thanks alot,
Itay.

Apr 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
itay_k wrote:
Hi,

I want to send a cookie on some http request (with urllib2),
so I created a Cookie but I cant associate it with CookieJar object.


You have to use a cookielib.Cookie, not Cookie.SimpleCookie():

import cookielib, urllib2

cj = cookielib.CookieJar()
cookie = cookielib.Cookie(...your cookie data here...)
cj.set_cookie(cookie)

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
urllib2.install_opener(opener)

data = urllib2.urlopen(...).read()

Kent
Apr 19 '06 #2

P: n/a
Kent Johnson <ke**@kentsjohnson.com> writes:
itay_k wrote:
Hi,

I want to send a cookie on some http request (with urllib2),
so I created a Cookie but I cant associate it with CookieJar object.


You have to use a cookielib.Cookie, not Cookie.SimpleCookie():


As I mention in the other thread Itay started, he probably doesn't
want to do that either.
John

Apr 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.