添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more

When trying to host an API on App Engine, the following error keeps coming up. The program used to run on Flask which was working but very slow.

Error:

"Traceback (most recent call last):
  File "/env/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/env/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
TypeError: __call__() missing 1 required positional argument: 'send'

Docker File:

FROM gcr.io/google_appengine/python
RUN apt-get update && apt-get install -y ffmpeg
# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
RUN virtualenv /env -p python3.7
# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Add the application source code.
ADD . /app
CMD gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

app.yaml

runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app
service: encoder
runtime_config:
  python_version: 3
handlers:
- url: /.*
  script: auto
                The error basically says you are trying to run FastAPI as WSGI which is not right and acceptable because FastAPI is only compatible with ASGI.  See this
– Yagiz Degirmenci
                Aug 15 '20 at 10:29
                So it runs, but now I get this error, "[error] 33#33: *92500 connect() failed (111: Connection refused) while connecting to upstream, client: 216.58.212.244, server: 
– Josh Bello
                Aug 17 '20 at 9:43

As Dustin said I found out that worker class need to be changed. Try the below one.

gunicorn -k uvicorn.workers.UvicornWorker main:app

Found this on github issues

App Engine requires your main.py file to declare an app variable which corresponds to a WSGI Application.

Since FastAPI is an asynchronous web framework, it is not compatible with WSGI (which is synchronous).

Your best option would be to use a service like Cloud Run, which would allow you to define your own runtime and use an asynchronous HTTP server compatible with FastAPI.

I am trying to find any info on how to configure Cloud Run to use an asynchronous HTTP server. Can anyone please guide me to the appropriate docs? Thanks. – Bellave Jayaram Dec 22 '20 at 19:25 @BellaveJayaram Since Cloud Run allows you to use any container image, there is nothing specific required to use an async HTTP server. If there was a particular server you wanted to use and weren't sure how to get started, I'd recommend asking a new question instead of leaving a comment here. – Dustin Ingram Dec 23 '20 at 18:05

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.