python requests 使用 ss 代理

1
2
3
4
5
6
7
8
proxies = {'http': 'socks5h://127.0.0.1:1086', 'https': 'socks5h://127.0.0.1:1086'}
result = requests.post(
<url>,
data=<data>,
headers=<headers>,
timeout=100, verify=False,
proxies=proxies
)

socks5 和 socks5h 的区别:

1
2
3
4
socks5h:
the hostname is resolved by the SOCKS server (also known as CURLPROXY_SOCKS5_HOSTNAME type);
socks5:
the hostname is resolved locally;