How do I implement SSL and CGIHTTPServer in Python 2.7? (SSL Error) -
How do I implement SSL and CGIHTTPServer in Python 2.7? (SSL Error) -
i'm trying implement ssl wrapped socket , cgihttpserver basehttpserver in python 2.7. had working simplehttprequesthandler need include cgi functionality.
the commented code previous iterations of i've been trying solve problem. if serverclass = httpserver
(see run()
), (error code: ssl_error_rx_record_too_long)
. if utilize serverclass = securehttpserver
, can load pages on port 80 connection resets on 443.
i'd appreciate help in getting ssl-enabled web server cgi support!
#!/usr/bin/env python import socket, os, sys socketserver import baseserver basehttpserver import httpserver cgihttpserver import * import cgitb; cgitb.enable() openssl import ssl class securehttpserver(httpserver): def __init__(self, server_address, handlerclass): baseserver.__init__(self, server_address, handlerclass) context = ssl.context(ssl.sslv23_method) pem = 'c:\serv\cert.pem' context.use_privatekey_file(pem) context.use_certificate_file(pem) self.socket = ssl.connection(context, socket.socket(self.address_family,self.socket_type)) self.server_bind() self.server_activate() class securehttprequesthandler(cgihttprequesthandler): cgi_directories = ['/cgi'] #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 run(handlerclass = securehttprequesthandler,serverclass = securehttpserver): server_address = ('localhost', 443) handler = cgihttprequesthandler server = serverclass(server_address, handler) sa = server.socket.getsockname() try: print "server ssl https on", sa[0], "port", sa[1], "..." server.serve_forever() except: server.socket.closed() if __name__ == '__main__': run()
python python-2.7 ssl webserver
Comments
Post a Comment