title: SSL in python3 with HTTPServer
body: <p>I found here a (apparently-)working HTTPS server for python 2: <a href="http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/?c=15536" rel="noreferrer">http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/?c=15536</a></p>
  
  <p>I'm trying to port it in python3 but I have no good results. This is my code:</p>
  
  <pre><code>from socketserver import BaseServer
  import string,cgi,time
  from os import curdir, sep
  from http.server import SimpleHTTPRequestHandler, HTTPServer
  import ssl
  import os # os. path
  import socket
  
  class SecureHTTPServer(HTTPServer):
      def __init__(self, server_address, HandlerClass):
          BaseServer.__init__(self, server_address, HandlerClass)
          ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
          #server.pem's location (containing the server private key and
          #the server certificate).
          fpem = 'certificate1.pem'
          ctx.load_verify_locations(fpem)
          self.socket = ctx.wrap_socket(socket.socket(self.address_family,
                                                          self.socket_type))
          self.server_bind()
          self.server_activate()
  
  
  class SecureHTTPRequestHandler(SimpleHTTPRequestHandler):
      def setup(self):
          self.connection = self.request
          self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
          self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
      def do_GET(self):
          print('get recieved!');
          self.send_error(404,'File Not Found: %s' % self.path)
  
  def test(HandlerClass = SecureHTTPRequestHandler,
           ServerClass = SecureHTTPServer):
      server_address = ('', 1443) # (address, port)
      httpd = ServerClass(server_address, HandlerClass)
      sa = httpd.socket.getsockname()
      print ("Serving HTTPS on", sa[0], "port", sa[1], "...")
      httpd.serve_forever()
  
  
  if __name__ == '__main__':
      test()
  </code></pre>
  
  <p>When I run it I get no errors, but when I connect to localhost:1443 (with https) I get no response and the <code>print('get recieved!');</code> is't triggered.</p>