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