1 year ago
#73654
kailashdesiti
how to https hosting in python http.server.SimpleHTTPRequestHandler
I am using python http.server.SimpleHTTPRequestHandler to create an http server using below code
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", str(PORT))
httpd.serve_forever()
We want this server to be accessed via https, so I found one solution online below is the code snippet for it
import http.server, ssl
server_address = ('localhost', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
server_side=True,
certfile='localhost.pem',
ssl_version=ssl.PROTOCOL_TLS)
httpd.serve_forever()
The problem for this approach is that, we will host is on many client machines and it should happen dynamically, so how can we generate the ssl certificates dynamically, and is there any way to host the server as https without providing any certificate file via this method.
python
python-3.x
https
openssl
ssl-certificate
0 Answers
Your Answer