ASGI Framework生命周期错误,如果没有生命周期支持,则会继续

时间:2019-11-06 13:07:19

标签: django quart

在使用django创建项目并通过chrome audit审核代码后,它会显示

  

不对所有资源使用HTTP / 2 2个请求未通过提供   HTTP / 2

要解决此错误,我已按照本教程进行操作

https://medium.com/python-pandemonium/how-to-serve-http-2-using-python-5e5bbd1e7ff1

以及使用夸脱指定的代码时

import ssl

from quart import make_response, Quart, render_template, url_for

app = Quart(__name__)

@app.route('/')
async def index():
    result = await render_template('index.html')
    response = await make_response(result)
    response.push_promises.update([
        url_for('static', filename='css/bootstrap.min.css'),
        url_for('static', filename='js/bootstrap.min.js'),
        url_for('static', filename='js/jquery.min.js'),
    ])
    return response


if __name__ == '__main__':
    ssl_context = ssl.create_default_context(
        ssl.Purpose.CLIENT_AUTH,
    )
    ssl_context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
    ssl_context.set_ciphers('ECDHE+AESGCM')
    ssl_context.load_cert_chain(
        certfile='cert.pem', keyfile='key.pem',
    )
    ssl_context.set_alpn_protocols(['h2', 'http/1.1'])
    app.run(host='localhost', port=5000, ssl=ssl_context)

我明白了

  

/home/avin/Documents/projects/portfolio/portfolio_env/lib/python3.6/site-packages/quart/app.py:1320:   UserWarning:尚不支持其他参数ssl
  “还没有其他参数{},   支持” .format(','。join(kwargs.keys())),在   https://localhost:5000(CTRL + C退出)[2019-11-06 18:30:18,586]   ASGI Framework生命周期错误,如果没有生命周期支持,则会继续发生

我也无法通过https://localhost:5000

加载网页

1 个答案:

答案 0 :(得分:0)

  

ASGI Framework生命周期错误,在没有生命周期支持的情况下继续发生

实际上只是警告,它指出Django尚不支持ASGI规范的寿命部分。不会造成任何问题(如摘录所示)。

您所引用的文章已经过时,this is an updated version。要使其适合您的代码段,只需将if语句更改为此(如下),它就可以工作,(尽管更新的文章显示了更好的方法)

...

if __name__ == '__main__':
    app.run(
        host='localhost', port=5000, certfile='cert.pem', keyfile='key.pem'
    )