flask想监听在HTTPS上面,但是运行报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

flask想监听在HTTPS上面,但是运行报错

睡着了去做梦 2021-10-21 11:17:14 165

部分代码

if __name__ == '__main__':
    # app.run(host="0.0.0.0",port=5004)
    app.run(host="0.0.0.0", port=443, ssl_context=(
        "/Users/jiangyd/Downloads/dc/ca/serevr.crt",
        "/Users/jiangyd/Downloads/dc/ca/server.key"))

报错如下

Traceback (most recent call last):
  File "app.py", line 76, in <module>
    "/Users/jiangyd/Downloads/dc/ca/serevr.crt",
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 922, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 1008, in run_simple
    inner()
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 957, in inner
    fd=fd,
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 781, in make_server
    host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 702, in __init__
    ssl_context = load_ssl_context(*ssl_context)
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 595, in load_ssl_context
    ctx.load_cert_chain(cert_file, pkey_file)
FileNotFoundError: [Errno 2] No such file or directory

https报错 flash报错 http监听 flask报错 ssh报错lang
分享到
取消 提交回答
全部回答(2)
  • 李烈火
    2021-10-22 10:38:18

    监听https需要配置正确的证书,要确定能使用的证书格式和位置

    0 0
  • 无敌小将
    2021-10-21 11:22:55

    您好,从图中意思可看出应该是SSL证书路径不对导致。您pyopenssl 模块安装的话,如果没有证书请生成证书:

    pip install pyopenssl
    
    
    openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
    
    1 0
添加回答
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

相似问题
最新问题