如何使用Python和fastapi修复beanstlak应用程序上的wsgi错误

2024-04-19 08:32:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python和fasatpi(web框架)。 我的application.py文件是:

from fastapi import FastAPI
import uvicorn

application = FastAPI()


@application.get("/")
def read_root():
    return {"Hello": "World"}



if __name__ == "__main__":
    uvicorn.run("application:application", host="127.0.0.1", port=5000, log_level="info")

通过运行python application.py,可以在本地计算机上正常运行

但是,当我在AWS上部署到elastic beanstalk时,在多次尝试失败并尝试使用Procfile之后,如下所示:

web: uvicorn application:app --host=0.0.0.0 --port=${PORT:-5000}

重复的错误是:

[

Tue Jun 16 08:58:16.659854 2020] [mpm_prefork:notice] [pid 8242] AH00163: Apache/2.4.43 (Amazon) mod_wsgi/3.5 Python/3.6.10 configured -- resuming normal operations
[Tue Jun 16 08:58:16.659870 2020] [core:notice] [pid 8242] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Tue Jun 16 08:58:19.704522 2020] [:error] [pid 8247] [remote 127.0.0.1:0] mod_wsgi (pid=8247): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.
[Tue Jun 16 08:58:19.704608 2020] [:error] [pid 8247] [remote 127.0.0.1:0] TypeError: __call__() missing 1 required positional argument: 'send'

我怎样才能解决这个问题?非常感谢


Tags: pyimportwebmodapphostwsgiapplication