opener = urllib.request.build_opener(SocksiPyHandler(socks.PROXY_TYPE_SOCKS4,
    'localhost', 9999))
print(opener.open('http://www.whatismyip.com/automation/n09230945.asp').read())
How can I use a SOCKS 4/5 proxy with urllib2?