Python 如何创建HTTPS龙卷风服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18307131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:26:54 来源:igfitidea点击:
How to create HTTPS tornado server
提问by j0shu4b0y
Please help me to create HTTPS tornado server My current code Python3 doesn't work
请帮我创建 HTTPS 龙卷风服务器我当前的代码 Python3 不起作用
import os, socket, ssl, pprint, tornado.ioloop, tornado.web, tornado.httpserver
from tornado.tcpserver import TCPServer
class getToken(tornado.web.RequestHandler):
def get(self):
self.write("hello")
application = tornado.web.Application([
(r'/', getToken),
])
# implementation for SSL
http_server = tornado.httpserver.HTTPServer(application)
TCPServer(ssl_options={
"certfile": os.path.join("/var/pyTest/keys/", "ca.csr"),
"keyfile": os.path.join("/var/pyTest/keys/", "ca.key"),
})
if __name__ == '__main__':
#http_server.listen(8888)
http_server = TCPServer()
http_server.listen(443)
tornado.ioloop.IOLoop.instance().start()
HTTPS is very important for me, please help
HTTPS 对我很重要,请帮忙
采纳答案by falsetru
No need to use TCPServer
.
无需使用TCPServer
.
Try following:
尝试以下操作:
import tornado.httpserver
import tornado.ioloop
import tornado.web
class getToken(tornado.web.RequestHandler):
def get(self):
self.write("hello")
application = tornado.web.Application([
(r'/', getToken),
])
if __name__ == '__main__':
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": "/var/pyTest/keys/ca.csr",
"keyfile": "/var/pyTest/keys/ca.key",
})
http_server.listen(443)
tornado.ioloop.IOLoop.instance().start()