编程语言
首页 > 编程语言> > python gunicorn -w 4 -b 0.0.0.0:8080 main:app 报错 TypeError: __call__() missing 1 required positional

python gunicorn -w 4 -b 0.0.0.0:8080 main:app 报错 TypeError: __call__() missing 1 required positional

作者:互联网

使用 gunicorn -w 4 -b 0.0.0.0:8080 main:app 运行时,报错 TypeError: __call__() missing 1 required positional argument: 'send'

from fastapi import FastAPI
app = FastAPI()
@app.post("/tet")
async def root():
    return {"message": "Hello World"}

运行命令:

gunicorn -k gevent --bind "0.0.0.0:8080" --log-level debug main:app
gunicorn -k tornado --bind "0.0.0.0:8080" --log-level debug main:app

报错信息

email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator
[2020-06-08 16:05:42 +0800] [12796] [DEBUG] 1 workers
[2020-06-08 16:05:49 +0800] [12799] [DEBUG] GET /tet
[2020-06-08 16:05:49 +0800] [12799] [ERROR] Error handling request /tet
Traceback (most recent call last):
  File "/home/ap/nlp/Anaconda3/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 56, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/home/ap/nlp/Anaconda3/lib/python3.6/site-packages/gunicorn/workers/ggevent.py", line 160, in handle_request
    addr)
  File "/home/ap/nlp/Anaconda3/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 107, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
TypeError: __call__() missing 1 required positional argument: 'send'

原因:

FastAPI only runs in an ASGI server. gunicorn only ships with implementations of the PEP 3333 WSGI standard. The two are not compatible.
FastAPI 仅在 ASGI 服务器中运行。gunicorn 仅附带 PEP 3333 WSGI 标准的实现。两者不兼容。

需要指定 uvicorn.workers.UvicornH11Worker

gunicorn -k uvicorn.workers.UvicornWorker --bind "0.0.0.0:8080" --log-level debug main:app

标签:__,gunicorn,--,0.0,app,报错,workers
来源: https://www.cnblogs.com/darling331/p/16371877.html