Skip to content

Instantly share code, notes, and snippets.

@vpack
Last active October 20, 2023 07:59
Show Gist options
  • Save vpack/2d5f3f89affcc58dac462edbfdd5c119 to your computer and use it in GitHub Desktop.
Save vpack/2d5f3f89affcc58dac462edbfdd5c119 to your computer and use it in GitHub Desktop.
Flask SSL Sample APP
from flask import Flask
from flask_sslify import SSLify
"""
Option 1 : (pip install pyopenssl)
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('web.key')
context.use_certificate_file('web.crt')
Option 2 : (OOB : No install)
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain('web.crt', 'web.key')
Option 3 : Native Flask (No imports needed)
"""
app = Flask(__name__)
context = ('web.crt', 'web.key')
sslify = SSLify(app)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
context = ('web.crt', 'web.key')
app.run( debug = True, ssl_context = context)
#app.run( debug = True, ssl_context = 'adhoc') # Generate Adhoc Certs
@TyLaneTech
Copy link

I'm having the same problem @antoniojsp @omarnazih
Any answers?

@LauraFgar
Copy link

Tengo el mismo problema, alguna solución?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment