can you add HTTPS functionality to a python flask web server?

后端 未结 6 2147
半阙折子戏
半阙折子戏 2020-11-28 03:46

I am trying to build a web interface to Mock up a restful interface on networking device this networking device uses Digest Authentication and HTTPS. I figured out how to in

6条回答
  •  时光说笑
    2020-11-28 04:18

    this also works in a pinch

    from flask import Flask, jsonify
    
    
    from OpenSSL import SSL
    context = SSL.Context(SSL.PROTOCOL_TLSv1_2)
    context.use_privatekey_file('server.key')
    context.use_certificate_file('server.crt')
    
    
    
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        return 'Flask is running!'
    
    
    @app.route('/data')
    def names():
        data = {"names": ["John", "Jacob", "Julie", "Jennifer"]}
        return jsonify(data)
    
    
    #if __name__ == '__main__':
    #    app.run()
    if __name__ == '__main__':  
         app.run(host='127.0.0.1', debug=True, ssl_context=context)
    

提交回复
热议问题