views:

356

answers:

2

Hello All

Happy New Year!

i have some question about python mechanize 's proxy support.

im making some web client script, and i would like to insert proxy support

function into my script.

for example ,if i have such like following some script.

how can i add proxy support into my mechanize script?

i was look for some reference , but not so much good hint from google.

params = urllib.urlencode({'id':id, 'passwd':pw})
rq = mechanize.Request("http://www.example.com" params) 
rs = mechanize.urlopen(rq)

whenever i open this 'www.example.com' website , i would like open go through proxy.

Thanks in advance!

+1  A: 

I'm not sure whether that help or not but you can set proxy settings on mechanize proxy browser.

br = Browser()
# Explicitly configure proxies (Browser will attempt to set good defaults).
# Note the userinfo ("joe:password@") and port number (":3128") are optional.
br.set_proxies({"http": "joe:[email protected]:3128",
                "ftp": "proxy.example.com",
                })
# Add HTTP Basic/Digest auth username and password for HTTP proxy access.
# (equivalent to using "joe:password@..." form above)
br.add_proxy_password("joe", "password")
poulejapon
Hi, thanks for your reply, but that is mechanize.browser module, that is some different what i look for method, im looking for mechanize .urlopen method thanks
paul
+1  A: 

You use mechanize.Request.set_proxy(host, type) (at least as of 0.1.11)

assuming an http proxy running at localhost:8888

req = mechanize.Request("http://www.google.com") req.set_proxy("localhost:8888","http") mechanize.urlopen(req)

Should work.