![](/img/trans.png)
[英]TypeError: __call__() missing 1 required positional argument: 'send' Django
[英]__call__() missing 1 required positional argument: 'send' FastAPI on App Engine
嘗試在 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'
"
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
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
正如達斯汀所說,我發現需要更改工人 class 。 試試下面的一個。
gunicorn -k uvicorn.workers.UvicornWorker main:app
在github 問題上找到了這個
App Engine 需要您的main.py
文件來聲明與WSGI Application對應的app
變量。
由於 FastAPI 是一個異步的 web 框架,它不兼容 WSGI(它是同步的)。
您最好的選擇是使用像Cloud Run這樣的服務,它允許您定義自己的運行時並使用與 FastAPI 兼容的異步 HTTP 服務器。
當我想將 FastAPI 應用程序部署到 Heroku 時,我遇到了同樣的問題。 實際上,您不能將uvicorn
(FastAPI 正在使用的 ASGI 框架)與使用 gunicorn 的gunicorn
一起使用。
但是,通過向 gunicorn 添加一個uvicorn
工作者, gunicorn
可以工作了::
gunicorn api:app --bind 0.0.0.0:$PORT --worker-class uvicorn.workers.UvicornWorker
我通過將python main.py
作為構建命令並將我的 uvicorn 命令在 main.py 中設置為uvicorn.run("main:app", host="0.0.0.0", port=8080)
解決了這個問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.