【发布时间】:2018-04-09 16:03:59
【问题描述】:
我有一个 Python (3.6) Tornado (4.5.2) 服务器的简单示例,我正在尝试添加 ssl 证书进行测试。我已经确定它正在查找密钥和 csr 文件。这是我的代码在详细说明错误后带有堆栈跟踪的样子。有没有人遇到过或者解决了?
import tornado.httpserver
import tornado.ioloop
import tornado.web
class indexHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello")
application = tornado.web.Application([
(r'/', indexHandler),
])
if __name__ == '__main__':
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": "cert/ig.csr",
"keyfile": "cert/ig.key",
})
http_server.listen(443)
tornado.ioloop.IOLoop.instance().start()
在 Python 3.6.4 上运行并且服务器运行,但是当页面以 https://localhost 访问时,它会引发以下异常。我错过了什么?
ERROR:asyncio:Exception in callback BaseAsyncIOLoop._handle_events(5, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(5, 1)>
Traceback (most recent call last):
File "/<python path>/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/<python path>/site-packages/tornado/platform/asyncio.py", line 102, in _handle_events
handler_func(fileobj, events)
File "/<python path>/site-packages/tornado/stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "/<python path>/site-packages/tornado/netutil.py", line 252, in accept_handler
callback(connection, address)
File "/<python path>/site-packages/tornado/tcpserver.py", line 264, in _handle_connection
do_handshake_on_connect=False)
File "/<python path>/site-packages/tornado/netutil.py", line 551, in ssl_wrap_socket
context = ssl_options_to_context(ssl_options)
File "/<python path>/site-packages/tornado/netutil.py", line 526, in ssl_options_to_context
context.load_cert_chain(ssl_options['certfile'], ssl_options.get('keyfile', None))
ssl.SSLError: [SSL] PEM lib (_ssl.c:3337)
在上面的错误信息中,/<python path>/ 等于:
"/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/"
【问题讨论】:
-
密钥文件是否为 PEM 格式?它与 Tornado 没有特别相关,因为错误是由
ssl库引发的,可能是因为密钥与证书不匹配或者它的格式不同。这是一个非常similar question。 -
Hello xyres - 密钥文件不是 PEM 格式(我认为是 AWS)。谢谢
标签: python-3.x https tornado