Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yongzhuo opened this issue Nov 8, 2019 · 5 comments
Closed

Comments

@yongzhuo
Copy link

yongzhuo commented Nov 8, 2019

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

or

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'
@jamadden
Copy link
Collaborator

jamadden commented Nov 8, 2019

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

@yongzhuo
Copy link
Author

yongzhuo commented Nov 8, 2019

@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?

@jamadden
Copy link
Collaborator

jamadden commented Nov 8, 2019

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

@yongzhuo
Copy link
Author

yongzhuo commented Nov 8, 2019

ok, thanks a lot!

@yongzhuo yongzhuo closed this as completed Nov 8, 2019
@danielwoerner
Copy link

danielwoerner commented Apr 1, 2022

@yongzhuo

are there any other ways?

the only other worker u can safely use is the uvicorn.workers.UvicornH11Worker which is meant for running in a PyPy environment

GalexY727 added a commit to GalexY727/spotify-now-playing that referenced this issue Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants