Ubuntu 14.04和12.04(全部经过测试),64位 pip install tornado(ver 4.1)
curl -X POST -v -k https://remote_ip:8080
错误如下: ```
ERROR:tornado.application:Exception in callback (<socket._socketobject object at 0x7fb670a4ad00>, <function null_wrapper at 0x7fb670a05aa0>)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 840, in start
handler_func(fd_obj, events)
File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 223, in accept_handler
callback(connection, address)
File "/usr/local/lib/python2.7/dist-packages/tornado/tcpserver.py", line 225, in _handle_connection
do_handshake_on_connect=False)
File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 470, in ssl_wrap_socket
return ssl.wrap_socket(socket, **dict(context, **kwargs))
File "/usr/lib/python2.7/ssl.py", line 489, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 243, in __init__
ciphers)
SSLError: _ssl.c:295: Both the key & certificate files must be specified
我的服务器代码如下所示: ```
import tornado
import tornado.web
import tornado.httpserver
import tornado.ioloop
class Docker(tornado.web.RequestHandler):
def post(self, *args, **kwargs):
self.write('1\n')
application = tornado.web.Application(
handlers=[
(r'/', Docker),
],
debug=True,
)
if __name__ == '__main__':
ssl_options={'certfile': 'certificate.crt',
'keyfile': 'privateKey.key'},
srv = tornado.httpserver.HTTPServer(application, xheaders=True, ssl_options=ssl_options)
srv.bind(8080)
srv.start()
tornado.ioloop.IOLoop.instance().start()
请注意,我使用openssl生成证书和密钥文件:
openssl genrsa -out privkey.pem 2048
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
特别是,当我在ssl_options dict中添加一个密钥时,cert_reqs = ssl.CERT_NONE,出现了更奇怪的错误:
文件/usr/local/lib/python2.7/dist-packages/tornado/netutil.py:
return ssl.wrap_socket(socket, **dict(context, **kwargs))
字典更新序列元素#0需要长度为1 2
我真的很想让我的龙卷风应用在HTTPS下正常运行,你能帮忙吗?
答案 0 :(得分:1)
ssl_options
的定义后,您有一个额外的逗号。这使ssl_options
元组包含字典而不是字典(参见Python tuple trailing comma syntax rule)。删除它,事情应该有效。