你可以添加HTTPS功能的python瓶Web服务器? [英] can you add HTTPS functionality to a python flask web server?
本文介绍了你可以添加HTTPS功能的python瓶Web服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了如何将摘要身份验证集成到Web服务器,但我似乎无法找到如何使用FLASK HTTPS,如果你能告诉我如何评论我需要做的下面的代码
from flask import烧瓶,jsonify
$ b $ app =烧瓶(__ name__)
@ app.route('/')
def index():
返回'Flask正在运行!'
@ app.route('/ data')
def names():
data = {names:[John,Jacob,Julie,Jennifer]}
return jsonify(data)
$ b if if __name__ =='__main__':
app.run()
解决方案
from flask导入Flask,jsonify
从OpenSSL导入SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file(' server.key')
context.use_certificate_file('server.crt')
$ b app = Flask(__ name__)
@ app.route('/')
def index():
return'Flask正在运行!'
@ app.route('/ data')
def name():
data = {names:[John,Jacob,Julie,Jennifer]}
return jsonify(data)
$ b #if __name__ = ='__main__':
#app.run()
if __name__ =='__main__':
app.run(host ='127.0.0.1',debug = True,ssl_context = context )
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 integrate Digest Authentication into the web server but I cannot seem to find out how to get https using FLASK if you can show me how please comment on what i would need to do with the code below to make that happen.
from flask import Flask, jsonify
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()
解决方案
this also works in a pinch
from flask import Flask, jsonify
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
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)
这篇关于你可以添加HTTPS功能的python瓶Web服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文