Posts

Showing posts from July, 2018

Setting up a HTTPS server in Python (WSGI)

The situation Setting up a HTTP server in Python is quite easy. You overload the handlers.CGIHandler class, and Bob's your uncle... You have to overload the  run  function, and that's about it. def run( self , host= 'localhost' , port= 8000 ): # Initialize the server deamon # HTTP self ._httpd = simple_server.make_server(host, port, self . __call__ ) print ( "Serving on port {0}..." .format(port)) # Start the server self ._httpd.serve_forever() Nothing to it, right? So, you'd expect that setting up a HTTPS server would also be a piece of cake... but it isn't that straightforward. Luckily, for you, I have spent some time to make this easy as frig. The idea is to make a SSL socket, and to do that, you have to use the  wrap_socket  command... but where? Look at this line of code from the  run  function self ._httpd = simple_server.make_server(host, port, self . __call__ ) When you open the  simple_server  p