当尝试在App Engine上托管API时,不断出现以下错误。该程序过去在Flask上运行,虽然工作正常,但速度非常慢。
错误:
"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文件:
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
发布于 2021-05-14 12:11:04
发布于 2020-08-18 02:36:34
App Engine要求您的main.py
文件声明一个对应于WSGI Application的app
变量。
由于FastAPI是一个异步web框架,所以它与WSGI (同步的)不兼容。
您最好的选择是使用像Cloud Run这样的服务,它允许您定义自己的运行时,并使用与FastAPI兼容的异步HTTP服务器。
https://stackoverflow.com/questions/63424042
复制相似问题