0

I have a python web application that is using FastAPI. It works locally, but when I deploy it to a free linux Azure App Service (using GitHub Actions) and try to load the site it says "Internal Server Error". When I pull up the application logs I see the following error message

2023-02-06T23:44:30.765055894Z [2023-02-06 23:44:30 +0000] [90] [ERROR] Error handling request /
2023-02-06T23:44:30.765101490Z Traceback (most recent call last):
2023-02-06T23:44:30.765109589Z   File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 136, in handle
2023-02-06T23:44:30.765116389Z     self.handle_request(listener, req, client, addr)
2023-02-06T23:44:30.765122088Z   File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2023-02-06T23:44:30.765128688Z     respiter = self.wsgi(environ, resp.start_response)
2023-02-06T23:44:30.765134688Z TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'

Any suggestions on how to fix this issue?

Austin
  • 4,638
  • 7
  • 41
  • 60
  • Error at the top thing says the lib is from python 3.11, while the bottom error is from python 3.10 - why? how? Imo first step would be to actually check the deployment process itself and lib versions compatibility. – h4z3 Feb 07 '23 at 14:09
  • @h4z3 Sorry, I accidentally pulled the top error from before I changed the app service and build environment to python 3.10 to match my local dev environment. I thought I was seeing the same error after the change, but it looks like that one is not coming up again. I'll update the question to remove that initial error. – Austin Feb 07 '23 at 16:25
  • 1
    Okay, so the error is because you're using gunicorn to run fastapi - gunicorn is wsgi, fastapi is asgi. Use uvicorn or change gunicorn's worker to use uvirorn - https://stackoverflow.com/questions/63424042/call-missing-1-required-positional-argument-send-fastapi-on-app-engine – h4z3 Feb 07 '23 at 16:33

1 Answers1

2

I was able to resolve this issue by adding the following custom startup command in the Azure App Service Configuration General Settings

python -m uvicorn app:app --host 0.0.0.0

As h4z3 pointed out, gunicorn is wsgi and fastapi is asgi so I had to change the startup command to use uvicorn. Additional details can be found in the Azure docs here: https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#example-startup-commands

Austin
  • 4,638
  • 7
  • 41
  • 60