Question about Python

Can I filter all outgoing connections through an HTTPS or SOCKS proxy? I have a script that uses various apis and calls scripts that use mechanize / urllib. I would like to filter out each connection through a proxy server by setting the proxy server in my "main" script (the one that calls all apis). Is it possible?

+3
source share
3 answers

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

Take a 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
+2
source

docs , urllib.urlopen() , - .

0

To use tor with mechanize, I use tor + polipo. set polipo use the parent proxy socksParentProxy = localhost: 9050 in the conf file. then use

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

where 8118 is your polypo port.

so you use polipo http proxy which uses sock to use tor

hope this helps :)

0
source

Source: https://habr.com/ru/post/1751691/


All Articles