It may be because, by default, requests is configured to resolve DNS queries on the local side of the connection.
Try changing your proxy URL from socks5://proxyhost:1234 to socks5h://proxyhost:1234. Note the extra h (it stands for hostname resolution).
import requests
# PySocks
proxies ={"http":"socks5h://127.0.0.1:1080","https":"socks5h://127.0.0.1:1080",}defdownload_file(url):
local_filename = url.split('/')[-1]# NOTE the stream=True parameter belowwith requests.get(url, stream=True, proxies=proxies)as r:
r.raise_for_status()withopen(local_filename,'wb')as f:for chunk in r.iter_content(chunk_size=8192):if chunk:# filter out keep-alive new chunks
f.write(chunk)# f.flush()return local_filename
download_file('https://www.google.com')