tags:

views:

24

answers:

2

Is it possible to filter all outgoing connections through a HTTPS or SOCKS proxy? I have a script that users various apis & calls scripts that use mechanize/urllib. I'd like to filter every connection through a proxy, setting the proxy in my 'main' script (the one that calls all the apis). Is this possible?

A: 

Just like the docs say, urllib.urlopen() looks to the system for proxy information, and also takes an optional argument for the proxies to use.

Ignacio Vazquez-Abrams
+1  A: 

Yes, you can put it in your code or take it from the envieonrment.

Look here http://docs.python.org/library/urllib.html

proxies = {'http': 'http://www.someproxy.com:3128'}
filehandle = urllib.urlopen(some_url, proxies=proxies)

Or

$ http_proxy="http://www.someproxy.com:3128"
$ export http_proxy
$ python yourScript.py 
OscarRyz