0

I have build a rest api with python flask.
I want change HTTP to HTTPS.
Like http://xx.domain.com:8700/v1/request to https://xx.domain.com/v1/request
What should I do? Where to set the certificate?
Here is part code.

if __name__ == '__main__':
    from waitress import serve
    serve(app, host="0.0.0.0", port=8700)
Haiyan
  • 46
  • 5

1 Answers1

1

If you would use plain flask it would be like this:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8700, ssl_context=('cert.pem', 'key.pem'))

Assumming that you have cert.pem and key.pem files on the same folders as the python script.

Dan Ionescu
  • 3,135
  • 1
  • 12
  • 17