0

I'm trying to make a simple TLS/SSL server/client in python (https://snyk.io/blog/implementing-tls-ssl-python/). However, I get the error:

Traceback (most recent call last):
  File "c:\Users\[USER]\Documents\Programming\Python\SSH Chat\test_server.py", line 7, in <module>
    httpd.socket = ssl.wrap_socket (httpd.socket,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[USER]\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 1443, in wrap_socket
    context.load_cert_chain(certfile, keyfile)
ssl.SSLError: [SSL] PEM lib (_ssl.c:3921)

Any ideas? Here's the code:

import ssl
import http.server
import requests

httpd = http.server.HTTPServer(('localhost', 443),
http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket,
certfile='SSH Chat/certificate.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLS)
httpd.serve_forever()

Thanks in advance.

  • It's a pretty generic error when something is wrong with the certificate and key you gave. Without detailed information about the certificate and key it is not possible to pinpoint the exact problem, so you are left with the more generic description in the duplicate questions. – Steffen Ullrich Sep 02 '23 at 19:47

0 Answers0