Python urllib over TOR? [duplicate]

The problem is that httplib.HTTPConnection uses the socket module’s create_connection helper function which does the DNS request via the usual getaddrinfo method before connecting the socket. The solution is to make your own create_connection function and monkey-patch it into the socket module before importing urllib2, just like we do with the socket class. import socks … Read more

Using a socks proxy with git for the http transport

I tested with Git 1.8.2 and SOCKS v5 proxy, following setting works for me: git config –global http.proxy ‘socks5://127.0.0.1:7070’ UPDATE 2017-3-31: According to the document, despite the name http.proxy, it should work for both HTTP and HTTPS repository urls. Thanks @user for pointing out this. UPDATE 2018-11-27: To disable the proxy, run command: git config … Read more

How can I use a SOCKS 4/5 proxy with urllib2?

You can use SocksiPy module. Simply copy the file “socks.py” to your Python’s lib/site-packages directory, and you’re ready to go. You must use socks before urllib2. (Try it pip install PySocks ) For example: import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, “127.0.0.1”, 8080) socket.socket = socks.socksocket import urllib2 print urllib2.urlopen(‘http://www.google.com’).read() You can also try pycurl lib and … Read more