Python 请求 - 尝试获取 presto 文档返回 sslv3 警报握手失败



我正在尝试获取Presto公共文档的内容,以便使用Python请求进行一些分析:

import requests
requests.get('https://prestodb.io/docs/current/functions/logical.html')

这将返回以下错误:

  File "/Users/my_user/PycharmProjects/untitled/test.py", line 3, in <module>
    requests.get('https://prestodb.io/docs/current/functions/logical.html')
  File "/Library/Python/2.7/site-packages/requests/api.py", line 71, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 57, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 477, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')],)",)

尝试使用openssl进行诊断,我发现该站点需要服务器名称指示:

openssl s_client -connect prestodb.io:443 -servername prestodb.io    // works
openssl s_client -connect prestodb.io:443                            // doesn't work
CONNECTED(00000003)
140735204868176:error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error:s23_clnt.c:769:

我做了很多搜索,并尝试了其他方法:

  • 我尝试使用此处所述的自定义HTTPAdapter将协议指定为TLSv1,但这无济于事。
  • 我也尝试直接使用 SSL 上下文和连接对象和set_tlsext_host_name但它也没有帮助。
  • 在我看来,要求是使用 TLSv1 和 SNI。但我无法通过请求获得它。有人可以帮我解决这个问题吗?提前谢谢。

    感谢卢卡斯·格拉夫,我根据 https://github.com/kennethreitz/requests/issues/2022 解决了这个问题。我实际上所做的是从Homebrew安装OpenSSL,然后从Homebrew安装新版本的Python 2,它将自动链接到Homebrew提供的OpenSSL:

    brew install openssl
    brew install python
    

    使用新安装的python,我能够获得presto文档页面。

    最新更新