Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create HTTPS tornado server

Please help me to create HTTPS tornado server My current code Python3 doesn't work

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

like image 568
j0shu4b0y Avatar asked Aug 19 '13 05:08

j0shu4b0y


People also ask

How do I run a tornado web server?

If you want to daemonize tornado - use supervisord. If you want to access tornado on address like http://mylocal.dev/ - you should look at nginx and use it like reverse proxy. And on specific port it can be binded like in Lafada's answer.

What is Tornado programming?

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

What is Tornado API?

Tornado is a Python web framework and asynchronous network library, originally developed at FriendFreed. Tornado uses non-blocking network-io. Due to this, it can handle thousands of active server connections. It is a saviour for applications where long polling and a large number of active connections are maintained.


1 Answers

No need to use 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() 
like image 53
falsetru Avatar answered Sep 22 '22 23:09

falsetru