【问题标题】:HTTPS proxies with Requests: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol带有请求的 HTTPS 代理:[Errno 8] _ssl.c:504:EOF 发生违反协议
【发布时间】:2013-06-02 14:17:22
【问题描述】:

我在 Windows 7 x64 上使用 Requests 1.2.3,并尝试使用 HTTPS 代理通过 HTTPS 连接到(任何)站点,方法是将 proxies 参数传递给请求。

我在使用urllib2ProxyHandler 时没有遇到此错误,所以我认为它不在我的代理端。

>>> 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

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

有什么建议吗?我查看了相关问题,但没有什么对我有用。

【问题讨论】:

  • 如果您像我一样在 2013 年 9 月之后遇到这个问题 - 那么请查看 requests 2.0.0。它有一个更好的 HTTPS 代理,因此它适用于所有代理。参考文献:stackoverflow.com/questions/18675872/…

标签: python ssl https proxy python-requests


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2015-05-13
    • 2016-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多