Gunicorn: TypeError: __call__() missing 1 required positional argument: 'send'

Created on 8 Nov 2019  路  4Comments  路  Source: benoitc/gunicorn

gunicorn + fastapi

fastapi:

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

gunicorn:

```
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

error:

email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator
[2019-11-08 16:05:42 +0800] [12796] [DEBUG] 1 workers
[2019-11-08 16:05:49 +0800] [12799] [DEBUG] GET /tet
[2019-11-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'

Most helpful comment

@jamadden
thanks, is that mean worker_class of gunicorn must be 'uvicorn.workers.UvicornWorker'?
like

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

are there any other ways?

All 4 comments

FastAPI only runs in an ASGI server. gunicorn only ships with implementations of the PEP 3333 WSGI standard. The two are not compatible.

@jamadden
thanks, is that mean worker_class of gunicorn must be 'uvicorn.workers.UvicornWorker'?
like

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

are there any other ways?

As far as I know, that's the only worker that implements ASGI instead of WSGI.

ok, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mw44118 picture mw44118  路  3Comments

ttcqaq picture ttcqaq  路  4Comments

Bogdanp picture Bogdanp  路  3Comments

benoitc picture benoitc  路  4Comments

zenglingyu picture zenglingyu  路  4Comments