1
import socket
sock = socket.socket()
sock.connect('somesite')

If I wanted the socket connect through a proxy, how would I do this? I don't see a relevant parameter or option in the docs.

user1447941
  • 3,675
  • 10
  • 29
  • 34
  • 1
    Seems like you'd just open a socket to the proxy, and work with the proxy's api to get through to the other side. – corsiKa Oct 18 '12 at 13:04
  • You can try using [SocksiPy](http://socksipy.sourceforge.net/): it will establish a connection to your proxy server and do all that work for you. – fecub Oct 18 '12 at 13:08
  • similar question: http://stackoverflow.com/questions/5148589/python-urllib-over-tor – Inbar Rose Oct 18 '12 at 13:25

1 Answers1

0

You first need to figure out what kind of proxy it is (SOCKS, HTTP, etc), and then either find a library that implements connections for that proxy type, or roll your own routine. The basic idea is you'll have your script connect to the proxy server/port, and then request the proxy to connect to the site you're trying to request.

If you don't want to do it like that, another viable option would be to use LD_PRELOAD to get it to connect transparently (under Linux), like torify does.

user1633448
  • 108
  • 7