我正在通过python中的flask创建一个普通的HTTP服务器。该程序应在普通计算机上运行。然后,移动应用程序将访问该Web服务器,并交换一些关键数据。
现在的问题是,如何确保连接的安全性。 代码段:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET'])
def result():
some_critical_data = request.form['data']
return 'Some other critical data'
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8071', debug=True)
答案 0 :(得分:0)
OpenSSL
很酷:
from flask import Flask, jsonify
from OpenSSL import SSL
context = SSL.Context(SSL. SSL.SSLv23_METHOD)
context.use_privatekey_file('server.key')
context.use_certificate_file('server.crt')
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET'])
def result():
some_critical_data = request.form['data']
return 'Some other critical data'
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8071', debug=True, ssl_context=context)