python request 连接一个收费HTTPS代理IP失败问题
当我不使用HTTPS或者使用使用别家的HTTPS代理是,都能正常,但是唯独使用这家的HTTPS时发生握手失败问题
proxies = {
'http':"http://175.172.81.174:5324",
'https':"http://175.172.81.174:5324",
}
import requests
r = requests.get("https://weibo.com/signup/signup.php",proxies=proxies,verify=False)
HTTPSConnectionPool(host='weibo.com', port=443): Max retries exceeded
with url: /signup/signup.php (Caused by SSLError(SSLError(1, u'[SSL:
UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:661)'),))
当使用下面代码时,每次都能成功:
from OpenSSL import SSL
import socket
proxies = {
'http':"http://175.172.81.174:5324",
'https':"http://175.172.81.174:5324",
}
headers = """GET https://weibo.com/signup/signup.php HTTP/1.1
Host: weibo.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: https://weibo.com/
Accept-Language: zh-CN,zh;q=0.8\r\n\r\n
"""
def verify_cb(conn, cert, errun, depth, ok):
return True
server = 'weibo.com'
port = 443
PROXY_ADDR = ("175.172.81.174", 5324)
CONNECT = "CONNECT %s:%s HTTP/1.1\r\nConnection: close\r\n\r\n" % (server, port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(PROXY_ADDR)
s.send(CONNECT)
print s.recv(4096)
ctx = SSL.Context(SSL.TLSv1_METHOD)
ctx.set_verify(SSL.VERIFY_PEER, verify_cb)
ss = SSL.Connection(ctx, s)
ss.set_connect_state()
ss.do_handshake()
cert = ss.get_peer_certificate()
print cert.get_subject()
ss.send(headers)
print ss.recv(3000)
ss.shutdown()
ss.close()
有办法让Requests正常使用这个代理IP吗,如果你愿意帮我测试,请提供给我你的IP,因为使用这个代理前需要授权
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
verify=
True
'https':"http://175.172.81.174:5324"
改为'https':"https://175.172.81.174:5324"