How To Create A localhost HTTPS Python Server

To create a python https server, create server.py in your development directory...

import BaseHTTPServer, SimpleHTTPServer
import ssl
    
httpd = BaseHTTPServer.HTTPServer(('', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='localhost.pem', server_side=True)
httpd.serve_forever()

And run python server.py to start the server. To generate the self signed certificate...

openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes

Make sure the "Common Name" is the same name as the server, e.g. "localhost"

Creating an HTTPS server in Python