Description
Is it possible to use FastAPI on Google AppEngine?
Additional context
I have tried a minimal project, with:
README.md, requirements.txt containing just fastapi and uvicornapp.yaml containing just runtime: python37When deploying, I get the following error:
Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 279, in handle
keepalive = self.handle_request(req, conn)
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 328, in handle_request
respiter = self.wsgi(environ, resp.start_response)
TypeError: __call__() takes 2 positional arguments but 3 were given
I have tried different variations, but I always end up with this error.
just shipped a minimal app here https://fastapi-minimal.appspot.com/docs
https://github.com/euri10/fastapi_appengine_minimal
most likely you're missing an entrypoint in your app.yaml
Thank you @euri10 ! You are right, the entrypoint is to blame.
For future reference, the following app.yaml results in the error above:
runtime: python37
entrypoint: gunicorn main:app
while the correct version is:
runtime: python37
entrypoint: gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
Thanks for your help @euri10 ! You should write a blog post about that :wink:
I'm glad you solved your issue @hiovidiu . Thanks for reporting back and closing the issue.
Why use gunicorn instead of uvicorn?
entrypoint: uvicorn main:app --port $PORT
just quoting uvicorn doc :+1:
Running with Gunicorn
Gunicorn is a mature, fully featured server and process manager.Uvicorn includes a Gunicorn worker class allowing you to run ASGI applications, with all of Uvicorn's performance benefits, while also giving you Gunicorn's fully-featured process management.
This allows you to increase or decrease the number of worker processes on the fly, restart worker processes gracefully, or perform server upgrades without downtime.
For production deployments we recommend using gunicorn with the uvicorn worker class.
gunicorn example:app -w 4 -k uvicorn.workers.UvicornWorker
For a PyPy compatible configuration use uvicorn.workers.UvicornH11Worker.For more information, see the deployment documentation.
I've noticed that I keep getting this error
Traceback (most recent call last):
File "uvloop/cbhandles.pyx", line 71, in uvloop.loop.Handle._run
File "uvloop/handles/tcp.pyx", line 152, in uvloop.loop.TCPTransport._call_connection_made
File "uvloop/handles/basetransport.pyx", line 131, in uvloop.loop.UVBaseTransport._call_connection_made
File "uvloop/handles/basetransport.pyx", line 128, in uvloop.loop.UVBaseTransport._call_connection_made
File "/env/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 125, in connection_made
self.client = get_remote_addr(transport)
File "/env/lib/python3.7/site-packages/uvicorn/protocols/utils.py", line 7, in get_remote_addr
info = socket_info.getpeername()
File "uvloop/pseudosock.pyx", line 104, in uvloop.loop.PseudoSocket.getpeername
OSError: [Errno 107] Transport endpoint is not connected
with app yaml like this
runtime: python37
entrypoint: gunicorn main:app -w 2 -k uvicorn.workers.UvicornWorker
Now my app does connect to Firestore and GCP buckets so maybe its more related to that. Anyways, any suggestions?
No one knows what that error means? It still occurs for me all the time.
Maybe it is related to gunicorn? https://github.com/benoitc/gunicorn/issues/1913
Most helpful comment
just quoting uvicorn doc :+1: