import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse
import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
socket.socket = socks.socksocket
url = 'http://ifconfig.me/ip'
request = urllib.request.Request(url)
request.add_header('Cache-Control', 'max-age=0')
response = urllib.request.urlopen(request)
print(response.read())
How to make HTTP request through a (tor) socks proxy using python?