在 heroku 中部署 FastAPI 时出现错误 h10

FastAPI deploy in heroku giving an error h10

我正在尝试在 heroku 上部署试用 fastAPI 应用程序:

from fastapi import FastAPI

app = FastAPI()

@app.get('/')

def get_root():
  return {'message': 'this is the root message'}

我的根文件夹如下所示:

venv/
main.py
Procfile
requierements.txt

inside main.py 我有上述代码,Procfile 包含;

web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}

和requierements.txt

fastapi

在日志中,当我访问根目录时,我看到;

2021-08-12T10:19:21.594055+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myappname.herokuapp.com request_id=7af272bc-7d23-41f3-a42e-afe380722f18 fwd="95.169.227.233" dyno= connect= service= status=503 bytes= protocol=https

首先,您应该将 requierements.txt文件名 中多了一个 'e')重命名为 requirements.txt。因为“如果您的应用程序在其根目录中包含 requirements.txt、setup.py 或 Pipfile 文件,Heroku 会自动将您的应用程序识别为 Python 应用程序。” (*)

然后您应该将 uvicorn 添加到您的 requirements.txt