3

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?

3 Answers 3

2

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

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 

Or

$[tsocks][1] yourScript.py
Sign up to request clarification or add additional context in comments.

1 Comment

does mechanize/urllib supports socks proxy?
0

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.

Comments

0

to use tor with mechanize I use tor+polipo. set polipo to use parent proxy socksParentProxy=localhost:9050 at confing file. then use

browser.set_proxies({"http": "localhost:8118"})

where 8118 is your polipo port.

so you are using polipo http proxy that uses sock to use tor

hope it helps :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.