带有请求的HTTPS代理:[Errno 8] _ssl.c:504:EOF违反协议 [英] HTTPS proxies with Requests: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

查看:501
本文介绍了带有请求的HTTPS代理:[Errno 8] _ssl.c:504:EOF违反协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7 x64上使用Requests 1.2.3并尝试使用HTTPS代理通过HTTPS连接到(任意)站点,方法是将 proxies 参数传递给使用 urllib2 ProxyHandler ,所以我认为这不在我的代理人一边。

 >>> opener = urllib2.build_opener(urllib2.ProxyHandler({'https':'IP:PORT'}))
>>> resp = opener.open('https://www.google.com')
>>> resp.url
'https://www.google.co.uk/'
>>> resp = requests.get('https://www.google.com',proxies = {'https':'IP:PORT'})
Traceback(最近一次调用最后一次):
文件 < stdin>,第1行,< module>
文件C:\Python27 \lib \site-packages \requests \ api.py,第55行,获取
返回请求('get',url,** kwargs )
文件C:\Python27 \lib \site-packages \requests \ api.py,第44行,请求
返回session.request(method = method,url = url,** kwargs)
文件C:\Python27 \lib \site-packages \requests\sessions.py,第335行,请求
resp = self.send( prep,** send_kwargs)
文件C:\Python27 \lib \site-packages \requests\sessions.py,第438行,发送
r = adapter.send(请求,** kwargs)
文件C:\Python27 \lib \site-packages \requests \ adapters.py,第331行,发送
加注SSLError(e)
requests.exceptions.SSLError:[Errno 8] _ssl.c:504:EOF违反协议发生

我应该注意,如果我将 verify = False 传递给th,仍然会发生同样的错误请求。



有任何建议吗?我看过相关的问题,但没有什么对我有用。

解决方案

我怀疑你的代理是一个http代理您可以使用https(常见情况)
问题是,如果请求本身https,请求使用https与代理进行通信。
为代理使用显式协议( http )应解决问题: proxies = {'https':'http:// IP :PORT'}



还可以查看 https://github.com/kennethreitz/requests/issues/1182


I am using Requests 1.2.3 on Windows 7 x64 and am trying to connect to (any) site via HTTPS using a HTTPS proxy by passing the proxies argument to the request.

I don't experience this error when using urllib2's ProxyHandler, so I don't think it's on my proxy's side.

>>> opener = urllib2.build_opener(urllib2.ProxyHandler({'https': 'IP:PORT'}))
>>> resp = opener.open('https://www.google.com')
>>> resp.url
'https://www.google.co.uk/'
>>> resp = requests.get('https://www.google.com', proxies={'https': 'IP:PORT'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\requests\api.py", line 55, in get
    return request('get', url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 331, in send
    raise SSLError(e)
requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

I should probably note that the same error still happens if I pass verify=False to the request.

Any suggestions? I've looked at related questions but there was nothing that worked for me.

解决方案

I suspect your proxy is a http proxy over which you can use https (the common case) The problem is, that requests uses https to talk to proxies if the request itself https. Using an explicit protocol (http) for your proxy should fix things: proxies={'https': 'http://IP:PORT'}

Also have a look at https://github.com/kennethreitz/requests/issues/1182

这篇关于带有请求的HTTPS代理:[Errno 8] _ssl.c:504:EOF违反协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆