程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Python Flask SSL 超时,非 SSL 没问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Python Flask SSL 超时,非 SSL 没问题?

开发过程中遇到Python Flask SSL 超时,非 SSL 没问题的问题如何解决?下面主要结合日常开发的经验,给出你关于Python Flask SSL 超时,非 SSL 没问题的解决方法建议,希望对你解决Python Flask SSL 超时,非 SSL 没问题有所启发或帮助;

我似乎在尝试使用 SSL 部署 Flask 应用时遇到问题

非 SSL 工作正常:

http://transcribe.22ai.net:5000/

但未能提供安全连接

https://transcribe.22ai.net:5000/

这是我的简单代码,证书来自 Let's Encrypt:

from flask import Flask,request
import ssl

app = Flask(__name__)

context = ssl.SSLContext()
context.load_cert_chain('fullchain.pem','privkey.pem')

'''
Flask Routes
'''
@app.route('/',methods=['GET'])

def index():

    return "Hello"

if __name__=='__main__':
    app.run(ssl_context=context)

有什么我遗漏的吗?

没有错误,输出如下:

2021-06-13 06:54:15 +0000] [27045] [INFO] Listening at: http://0.0.0.0:5000 (27045)
[2021-06-13 06:54:15 +0000] [27045] [INFO] Using worker: geventwebsocket.gunicorn.workers.GeventWebSocketWorker
[2021-06-13 06:54:15 +0000] [27053] [INFO] BooTing worker with pID: 27053
[2021-06-13 06:54:15 +0000] [27054] [INFO] BooTing worker with pID: 27054
[2021-06-13 06:54:15 +0000] [27057] [INFO] StarTing gunicorn 20.1.0

提前致谢。

解决方法

这是按照 Steffen 的建议运行的更新后的命令行。

gunicorn -b 0.0.0.0:5000 wsgi:app --certfile fullchain.pem --keyfile privkey.pem —-error-logfile ./logs/error.log --capture-output --log-level debug

大佬总结

以上是大佬教程为你收集整理的Python Flask SSL 超时,非 SSL 没问题全部内容,希望文章能够帮你解决Python Flask SSL 超时,非 SSL 没问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。