27

请帮我创建 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对我来说很重要,请帮忙

4

1 回答 1

47

无需使用TCPServer.

尝试以下操作:

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()
于 2013-08-19T06:05:39.903 回答