简体   繁体   English

ASGI“寿命”协议似乎不受支持

[英]ASGI 'lifespan' protocol appears unsupported

I have an asynchronous code running on fastapi & aiofiles i'm trying to load and save my info from a .json file but every time I shut down the program, it save only the keys of the dict and showing me "ASGI 'lifespan' protocol appears unsupported" massage我有一个在 fastapi 和 aiofiles 上运行的异步代码,我试图从 .json 文件加载和保存我的信息,但是每次我关闭程序时,它只保存字典的键并显示“ASGI 'lifespan'协议似乎不受支持”按摩

this is my turn on/off part:这是我的开启/关闭部分:

@app.on_event("startup")
async def startup_event():
    global beers
    try:
        async with aiofiles.open("data.json", mode='r+', json=True) as file:
            beers = await file.read()
    except:
        beers = {}


@app.on_event("shutdown")
async def on_exit_app():
    async with aiofiles.open("data.json", "w+") as outfile:
        await outfile.write(beers)

any ideas where is the problem?任何想法问题出在哪里?

This 99% means that something in the on_event("shutdown") function throws an error that isn't caught by the server (FastAPI/Starlette), and the app crashes, instead of ending properly.这 99% 意味着on_event("shutdown")函数中的on_event("shutdown")引发了服务器(FastAPI/Starlette)未捕获的错误,并且应用程序崩溃,而不是正确结束。 This leads uvicorn to believe that the server doesn't support the livespan part of the ASGI protocol.这导致 uvicorn 相信服务器不支持 ASGI 协议的 livespan 部分。

If you run uvicorn with additional option --lifespan on , the error will be shown and you can debug it.如果您使用附加选项--lifespan on运行uvicorn ,则会显示错误,您可以对其进行调试。

See Starlette bug report .请参阅Starlette 错误报告

It is just an assertion you can omit that, as far as I understand you are using Uvicorn as an HTTP server, since FastAPI is built top on an ASGI framework and Uvicorn is an ASGI HTTP server, there are some protocols on it.这只是一个你可以省略的断言,据我所知,你使用 Uvicorn 作为 HTTP 服务器,因为 FastAPI 构建在 ASGI 框架之上,而 Uvicorn 是一个 ASGI HTTP 服务器,它上面有一些协议。 ASGI protocol has support for http, websocket. ASGI 协议支持 http、websocket。

Uvicorn sets lifespan's value to auto and the assertion comes from there. Uvicorn 将 lifespan 的值设置为auto并且断言来自那里。

if self.config.lifespan == "auto":
    msg = "ASGI 'lifespan' protocol appears unsupported."

But you can use --lifespan on to fix that.但是你可以使用--lifespan on来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:不支持的pickle协议:4个带有pandas - ValueError: unsupported pickle protocol: 4 with pandas Python 3.7 错误:不支持的 Pickle 协议 5 - Python 3.7 Error: Unsupported Pickle Protocol 5 如何解决ValueError:不支持的pickle协议:4 - How to resolve ValueError: unsupported pickle protocol: 4 python-telegram-bot 不支持的 url 协议 - a python-telegram-bot Unsupported url protocol Python cassandra驱动程序:协议版本无效或不受支持:4 - Python cassandra driver: Invalid or unsupported protocol version: 4 树莓派的 MQTT 问题,SSL:UNSUPPORTED_PROTOCOL] 不受支持的协议 (_ssl.c:1056) - MQTT problem with raspberry pi, SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056) python ssl ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] 不支持的协议 (_ssl.c:590) - python ssl ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:590) ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] 不支持的协议 (_ssl.c:1108) - ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108) IOError:运行yum命令时不支持的XML-RPC协议 - IOError: unsupported XML-RPC protocol while running yum command ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] 在 Docker Python:3.6-slim 中不受支持的协议 (_ssl.c:852) - ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:852) in Docker Python:3.6-slim
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM