V
V
Vladislav Mukhin2021-11-15 22:50:53
Python
Vladislav Mukhin, 2021-11-15 22:50:53

How to properly connect an ssl certificate, and is it possible to run the server on my PC?

How can I connect an ssl certificate to a server in python.
In this case, I tried to install a certificate on the site from which communication with the server will take place
On the server (on the PC), files were created, such as: cert.pem, chain.pem, etc.
I connect these files, Example:

if __name__ == '__main__':
    if config.SSL_KEY:
        ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
        ssl_context.load_cert_chain(config.SSL_CHAIN, config.SSL_KEY)
        start_server = websockets.serve(handler, config.IP, config.PORT, ssl=ssl_context)
    else:
        start_server = websockets.serve(handler, config.IP, config.PORT)
    asndf = asyncio.get_event_loop()
    asndf.run_until_complete(start_server)
    asyncio.get_event_loop().run_forever()

ssl from config:
SSL_CHAIN = "C:\\Certbot\\live\\chat-messenger-kot.herokuapp.com\\cert.pem"
SSL_KEY = "C:\\Certbot\\live\\chat-messenger-kot.herokuapp.com\\privkey.pem"

On the client itself, I changed the protocol "ws" to "wss"
The client is hosted by heroku
When loading the page, an error occurs: I'm not sure if I'm doing everything right, any help would be appreciated, thanks :3
WebSocket connection to "wss://IP:PORT" failed:

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question