requests 配置代理后提示'Failed to establish a new connection: [Errno -2] Name or service not known'
socks5
换成socks5h
Using the schema socks5 results in DNS resolution happening on the client and not on the proxy. This corresponds to curl, which uses a scheme to decide whether to do DNS resolution on the client or proxy. If you want to allow domains on the proxy, use socks5h as schema.
socks5: DNS解析不经过代理
socks5h: DNS解析也经过代理
解决方法:
import requests
session = requests.session()
session.proxies = {'http': 'socks5h://127.0.0.1:9150', 'https': 'socks5h://127.0.0.1:9150'}
response = session.get("https://3g2upl4pq6kufc4m.onion/")
print(response)
#<Response [200]>