'Flask + gevent.pywsgi.WSGIServer + failed with SSLError + namecheap

So I have this web application running with Python's Flask and I use gevent.pywsgi.WSGIServer in order to make my application ready for production. My website is accessible from the Internet with all my devices and even others with different networks. However I tried to add the HTTPS possibility by running the test with certbot letsencrypt... I passed the tests and obtain the certfile and keyfile but when I put them as arguments in the following function :

app_server = gevent.pywsgi.WSGIServer(
    (CONFIG['Flask']['host'], int(CONFIG['Flask']['port'])),
    app,
    certfile="fullchain.pem",
    keyfile="privkey_rsa.pem"
)

Well I get this error ssl.SSLError: [SSL] PEM lib.

PS: I opened my port for HTTPS server

That's why I wonder if the problem comes from:

  • the domain name passed for the letsencrypt test
  • domain name registrar ... Or something else?

Thank you in advance.



Solution 1:[1]

I know this question is old and I came here looking for an answer to something else, but I have gone through your exact situation and couldn't help answering it.

I actually resolved the situation the proper way of building a website. I registered with a free dns server and routed all traffic coming to my router on ports 80/443 to a virtual machine in the LAN running NGINX, where I had already setup letsencrypt certs. Using this setup I don't have to enable SSL on any other machine in the network. Off topic, but to enable local network level ssl you need to have all the machines in the network. But you can simply forward requests from NGINX to any machine running in your local network using http and to the outside world all the traffic happens over SSL.

NGINX configuration is simple for LAN and you can create one yourself with a little google search, but the basic structure contains one server and several child location blocks where each location block corresponds to one web application in the LAN.

Hope this helps a bit. I can put a more detailed answer with specific steps if you are still looking.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SneakyPigeon