Python requests socks代理

更新requests 为支持socks的版本:

pip install -U requests[socks]

测试代码:

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

本文标题: 《Python requests socks代理》

本文链接地址: http://h4ck.org.cn/2020/10/python-requests-socks%e4%bb%a3%e7%90%86/

分享文章:

猜你喜欢:

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注