我做了一个简单的python烧瓶程序:
# save this as app.py
from flask import request
from flask import Flask
app = Flask(__name__)
@app.route("/", methods=['POST'])
def hello():
return "Hello, World!"
@app.route("/sms", methods=['POST'])
def sms():
print(request.get_json())
return "sms world"
if __name__ == '__main__':
app.run(port=443, host='0.0.0.0', ssl_context='adhoc')
当我执行命令 flask run
时,我得到以下信息:
答案 0 :(得分:0)
pip install pyopenssl
当您运行脚本时(或者如果您愿意,可以从 flask run 开始),您会注意到 Flask 表明它正在运行一个 https:// 实例
答案 1 :(得分:0)
首先使用以下命令安装 pyopenssl
:
pip install pyopenssl
要在 https 中启动它,只需添加参数:ssl_context='adhoc'
if __name__ == '__main__':
app.run(port=443, host='0.0.0.0', ssl_context='adhoc')
启动后将显示以下消息:
* Serving Flask app 'test' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on https://192.168.0.62:443/ (Press CTRL+C to quit)
显然,一旦应用程序投入生产,将不再需要此参数,但您必须将 wsgi 设置为在 https 中进行通信
答案 2 :(得分:0)
你可以试试 ngrok,它是一个有用的工具,可以将 HTTPS 和 HTTP 服务从本地部署到公共网络。