我已经尝试了此问答中的所有方法来解决它,但我仍然收到该错误。
我最近的尝试是基于Lukasa 的评论,我的代码如下所示:
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 中运行良好)