问题描述
我已经在 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上的所有Requests版本中,不支持通过代理请求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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!