requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF 发生违反协议 [英] requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

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

问题描述

我已经尝试了所有关于这个q&a 来解决它,但我仍然收到那个错误.

I have tried everything on this q&a to solve it but I still receive that error.

我最近的尝试基于 Lukasa 的评论,我的代码如下所示:

My latest attempt is based on Lukasa's comment and my code looks like this:

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl

class MyAdapter(HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = PoolManager(num_pools=connections,
                                       maxsize=maxsize,
                                       block=block,
                                       ssl_version=ssl.PROTOCOL_TLSv1)

proxy = 'https://78.130.136.2:8080'
g = 'https://www.google.com/'


s = requests.Session()
s.mount('https://', MyAdapter())

r = s.get(g, proxies={'https': proxy} )
print r.text.encode('utf-8')

我收到的完整错误是:

Traceback (most recent call last):
  File "/Users/Dionysis_Lorentzos/Projects/getter/proxy.py", line 30, in <module>
    r = s.get(g, proxies={'https': proxy}, verify=True )
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 347, in get
    return self.request('GET', url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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

那么如何通过 https 使用代理获取站点数据?(代理在我的 Firefox 中工作正常)

So how can I get the site's data with the proxy over the https? (the proxy works fine in my Firefox)

推荐答案

在 PyPI 上的请求的所有版本中,都不支持通过代理请求 HTTPS 站点,因为不支持CONNECT 动词.我们 2.0 的预发布分支有这种支持,它适用于我尝试过的每个代理.如果您想检查一下并尝试使用它,那么您也不需要自定义适配器.

In all of the versions of Requests on PyPI there is no support for requesting HTTPS sites over a proxy since there is no support for the CONNECT verb. Our pre-release branch for 2.0 has this support and it works on every proxy I have tried. If you wish to check that out and try it with this, then you won't need the custom adapter either.

否则,您将不得不等到我们发布 2.0

Otherwise, you will have to wait until we release 2.0

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

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