Python SOCKS5代理客户端HTTPS
我试图通过HTTPS上的SOCKS5代理服务器发出请求,但它失败或返回空字符串。我正在使用Python SOCKS5代理客户端HTTPS,python,python-2.7,https,proxy,socks,Python,Python 2.7,Https,Proxy,Socks,我试图通过HTTPS上的SOCKS5代理服务器发出请求,但它失败或返回空字符串。我正在使用PySocks库 这是我的例子 WEB_SITE_PROXY_CHECK_URL = "whatismyipaddress.com/" REQUEST_SCHEMA = "https://" host_url = REQUEST_SCHEMA + WEB_SITE_PROXY_CHECK_URL socket.connect((host_url, 443)) req
PySocks
库
这是我的例子
WEB_SITE_PROXY_CHECK_URL = "whatismyipaddress.com/"
REQUEST_SCHEMA = "https://"
host_url = REQUEST_SCHEMA + WEB_SITE_PROXY_CHECK_URL
socket.connect((host_url, 443))
request = "GET / HTTP/1.1\nHost: " + host_url + "\nUser-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11\n\n"
socket.send(request)
response = socket.recv(4096)
print response
但它不工作,它打印一个空字符串响应
在Python中有没有办法通过socks5代理发出HTTPS请求
谢谢
截至2016年4月29日发布的请求版本2.10.0,请求
支撑袜子
它需要PySocks,可以与pip安装PySocks一起安装
请注意,使用SOCKS代理时,request SOCKS将发出包含完整URL的HTTP请求(例如,
GET example.com HTTP/1.1
而不是GET/HTTP/1.1
),此行为可能会导致问题 你能提到你导入的库吗?看看这个@AakashVerma谢谢提供的解决方案很好,请将你的评论作为答案发布好的。很乐意帮忙:)
import requests
host_url = 'https://example.com'
#Fill in your own proxies' details
proxies={http:'socks5://user:pass@host:port',
https:'socks5://user:pass@host:port'}
#define headers if you will
headers={}
response = requests.get(host_url, headers=headers, proxies=proxies)