更新requests 为支持socks的版本:
代码语言:javascript复制pip install -U requests[socks]
测试代码:
代码语言:javascript复制import requests
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
}
proxies = {
#'socks5': '127.0.0.1:8889'
'http':'socks5://127.0.0.1:8889',
'https':'socks5://127.0.0.1:8889'
}
url = 'http://nkm3s8.xyz/'
try:
print('Proxy:')
res = requests.get(url, headers=headers, proxies=proxies, timeout=10)
print(res)
except Exception as e:
print(e)
try:
print('No Proxy:')
res = requests.get(url, headers=headers, timeout=10)
print(res)
except Exception as e:
print(e)
☆文章版权声明☆
* 网站名称:obaby@mars * 网址:https://h4ck.org.cn/ * 本文标题: 《Python requests socks代理》 * 本文链接:https://h4ck.org.cn/2020/10/python-requests-socks代理/ * 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。