How to route urllib requests through the TOR network?
This works for me (using urllib2, haven't tried urllib):
def req(url):
proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
return opener.open(url).read()
print req('http://google.com')