Вот два варианта. Первый через urllib, второй через requests.
import time
import requests
import urllib.request
import socket
import socks
import locale
import warnings
start_time = time.time()
locale.setlocale(locale.LC_ALL, '')
warnings.filterwarnings('ignore')
url = 'http://ifconfig.io/ip'
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", port=9050)
socket.socket = socks.socksocket
res = urllib.request.urlopen(url).read()
print (res.decode())
end = round(time.time() - start_time, 2)
print(f'--- {end} seconds ---')
start_time = time.time()
proxy = {
'http': 'http://111.68.26.237:8080',
'https': 'https://111.68.26.237:8080'
}
addr = requests.get(url, proxies=proxy).text
print (addr)
end = round(time.time() - start_time, 2)
print(f'--- {end} seconds ---')
Мдя, через TOR намного быстрее.
209.141.57.164
--- 0.82 seconds ---
111.68.26.237
--- 14.54 seconds ---