__call __ () thiếu 1 đối số vị trí bắt buộc: 'send' FastAPI trên App Engine

Aug 15 2020

Khi cố gắng lưu trữ một API trên App Engine, lỗi sau vẫn tiếp tục xuất hiện. Chương trình từng chạy trên Flask đang hoạt động nhưng rất chậm.

Lỗi:

"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'
"

Tệp 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

Trả lời

1 DustinIngram Aug 18 2020 at 01:36

App Engine yêu cầu main.pytệp của bạn khai báo một appbiến tương ứng với Ứng dụng WSGI .

Vì FastAPI là một khuôn khổ web không đồng bộ, nó không tương thích với WSGI (là đồng bộ).

Lựa chọn tốt nhất của bạn là sử dụng một dịch vụ như Cloud Run , cho phép bạn xác định thời gian chạy của riêng mình và sử dụng máy chủ HTTP không đồng bộ tương thích với FastAPI.