1

我正在尝试使用 tornado 的 http 客户端来获取 URL。我以前做过很多次,但这次我遇到了一个非常奇怪的 SSL 错误。我尝试使用的端点没有有效的证书,但是 curl 调用上的 -k 仍然证明它有效。

$ curl https://myhostname.com:9001
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

$ curl https://myhostname.com:9001 -k
404 page not found

我在网上找到的所有答案都建议将 validate_cert 设置为 False(我已经在这样做了)。但是当我尝试做我认为在 tornado 的 httpclient (validate_cert=False) 中等效的操作时,我仍然遇到一个非常奇怪的错误。这是一段测试代码中断:

import tornado.httpclient

request = tornado.httpclient.HTTPRequest(
    url="https://myhostname.com:9001",
    method="GET",
    validate_cert=False
)
print tornado.httpclient.HTTPClient().fetch(request)

结果如下:

WARNING:tornado.general:SSL Error on 6 ('myhostname.com', 9001): [Errno 1] _ssl.c:499: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Traceback (most recent call last):
  File "./test.py", line 17, in <module>
    make_call()
  File "/Users/kaleb.pomeroy/workspace/lefty/dashboard/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/gen.py", line 140, in wrapper
    result = func(*args, **kwargs)
  File "./test.py", line 13, in make_call
    response = tornado.httpclient.HTTPClient().fetch(request)
  File "/Users/kaleb.pomeroy/workspace/lefty/dashboard/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/httpclient.py", line 85, in fetch
    self._async_client.fetch, request, **kwargs))
  File "/Users/kaleb.pomeroy/workspace/lefty/dashboard/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/ioloop.py", line 370, in run_sync
    return future_cell[0].result()
  File "/Users/kaleb.pomeroy/workspace/lefty/dashboard/lib/python2.7/site-packages/tornado-3.1-py2.7.egg/tornado/concurrent.py", line 65, in result
    raise self._exception
tornado.httpclient.HTTPError: HTTP 599: [Errno 1] _ssl.c:499: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

不幸的是,我的端点不是公开的,因此我无法提供用于生成此错误的确切代码。

有没有人看到这个错误,或者有解决方案?

谢谢

4

1 回答 1

1

这看起来可能与https://github.com/facebook/tornado/blob/fd4d8997a7728​​29b8439322dbce45091bc51beaf /tornado/simple_httpclient.py#L196 上的逻辑有关 这是一个已知问题,tornado.simple_httpclient无法连接到 Python 2.6 上的某些服务器,并且这看起来像相同的错误消息,但我之前在 Python 2.7 上没有看到过这种失败。

尝试传递ssl_options={"ssl_version": ssl.PROTOCOL_TLSv1}给 HTTP 请求。您还可以尝试tornado.curl_httpclient另一种实现,它更有可能处理不太常见的服务器配置。

于 2013-09-26T04:41:54.233 回答