1

I want my visitors to be able to use both HTTP and HTTPS. I am using a simple Python webserver created with socket. I followed this guide: Python Simple SSL Socket Server, but it wasn't that helpful because the server would crash if the certificate cannot be trusted in one of the clients. Here is a few lines of code from my webserver that runs the server: def start(self): # create a socket object s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # bind the socket object to the address and port
    s.bind((self.host, self.port))
    # start listening for connections
    s.listen(100)

    print("Listening at", s.getsockname())
    while True:
        # accept any new connection
        conn, addr = s.accept()
        # read the data sent by the client (1024 bytes)
        data = conn.recv(1024).decode()
        pieces = data.split("\n")
        reqsplit = pieces[0].split(" ");
        # send back the data to client
        resp = self.handleRequests(pieces[0], pieces);
        conn.sendall(resp)

        # close the connection
        conn.close()

1 Answer 1

0

Have another service (something like nginx) handle the https aspect, then configure the service to reverse proxy to your python server

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.