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

Proxy + cookie: urllib2? httplib2? Other?

P: n/a
Hello

I need a library that supports both going out through a proxy, and
handling cookies automagically (the server uses a sessionID to keep
track of the user).

UrlLib2 supports the proxy part, httplib2 supports the cookie part
but... Google didn't return code that shows both uses in the same
library. Does someone know if either of those, or yet some other
library would support both features?

Thank you.
Nov 14 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Fri, 14 Nov 2008 16:03:13 +0100, Gilles Ganault <no****@nospam.com>
wrote:
>I need a library that supports both going out through a proxy, and
handling cookies automagically (the server uses a sessionID to keep
track of the user).
For those interested, it seems like a good combination is urllib2 +
cookielib:

==========
import urllib2
import cookielib

#Set up proxy infos
proxy_info = { 'host' : 'localhost','port' : 8119}
proxy_support = urllib2.ProxyHandler({"http" :
"http://%(host)s:%(port)d" % proxy_info})

#Set up cookie handler
cj = cookielib.CookieJar()

#Create UrlLib2 opener
opener =
urllib2.build_opener(proxy_support,urllib2.HTTPCoo kieProcessor(cj))
urllib2.install_opener(opener)

headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows
NT)' }
url = 'http://www.acme.com'
req = urllib2.Request(url, None, headers)

response = urllib2.urlopen(req).read()

for index, cookie in enumerate(cj):
print index, ' : ', cookie
==========

HTH,
Nov 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.