【问题标题】:heroku application error for fastapi (python)fastapi(python)的heroku应用程序错误
【发布时间】:2021-08-27 15:08:11
【问题描述】:

我关注了 github/stackoverflow 资源,观看了 youtube 视频,阅读了 heroku 官方文档,但最后我仍然遇到错误(网络错误)。有人可以帮我看看我的项目出了什么问题吗?

我在 github 上上传了项目并与 heroku 链接。使用环境变量作为带有数据库字符串的 heroku 配置变量、带有项目密钥的项目等。

我的 requirements.txt 文件如下

appdirs
typing
dnspython
email-validator
fastapi
motor
datetime
jose
passlib
dataclasses
typing-extensions
pydantic
starlette
uvicorn
bson
gunicorn
h11
click
pylint
astroid
websockets

Procfile 我在每个不同的提交中都写了这个 web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app 然后这个 web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000} 还有这个 web: uvicorn main:app --host="0.0.0.0" --port=${PORT:-8000} 并且 web: uvicorn main:app --host "0.0.0.0" --port ${PORT} 但它们都不可行。 并且还使用不同的 python 版本多次更新了 runtime.txt 文件。

我可能尝试了互联网上的所有可能性,但该死的问题是什么?

【问题讨论】:

  • 您确定您的 FastAPI 应用程序位于顶级 main.py 文件中吗?您可以使用相同的命令在本地运行您的服务器吗?还要检查您在 Heroku 中的日志。
  • 是的,我的应用在本地运行良好。我的应用实例 (app = FastAPI()) 位于我的 main.py 文件中
  • 检查 Heroku 中的日志。如果里面有什么有用的,请分享
  • 看不到。它发生: › 错误:缺少必需的标志: › -a, --app APP 应用程序运行命令 › 查看更多帮助 --help
  • 我可以假设,您的依赖项没有正确安装。调用 pip freeze > requirements.txt。出于某种原因,您的 requirements.txt 中没有固定版本。可能,您的 heroku 应用程序会获取需要 --app 标志的旧/新版本

标签: python heroku fastapi


【解决方案1】:

您必须通过从终端运行此命令来检查日志。 “heroku 日志 --tail -a [应用程序名称]”。

在我的情况下,问题是我从日志中找到的这个“pip install”pymongo[srv]”。解决方案是在 requirements.txt 中添加这个“dnspython==2.1.0”并重新部署。

【讨论】:

    猜你喜欢
    • 2020-07-31
    • 2023-03-09
    • 2022-07-14
    • 1970-01-01
    • 2011-12-18
    • 2013-08-25
    • 1970-01-01
    • 2021-06-21
    • 2016-04-01
    相关资源
    最近更新 更多