python SimpleHTTPServer ssl

Developer from somewhere

Problem: wanted to serve some assets over https using SimpleHTTPServer.

Solution: used info from here and here

  • following snippet combines both of those links:
import BaseHTTPServer, SimpleHTTPServer
import ssl

httpd = BaseHTTPServer.HTTPServer(('localhost', 8090), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='~/ssl/server.crt', 
  keyfile='~/ssl/server.key', server_side=True)
httpd.serve_forever()