在Heroku上部署Python 3(fastapi)应用程序不断失败

发布于 2025-01-20 21:38:27 字数 1872 浏览 2 评论 0 原文

这是我第一次使用Heroku,我正在尝试部署使用FastApi构建的Python应用程序。 在本地运行该应用程序时,一切都很好,代码本身应该没有问题。

我创建了包含: Web:Uvicorn App.main:App -host = 0.0.0.0 -port = $ {port:-5000}

我已经为git添加了所有内容,做了git commit-command,并将其全部推向了git。

当一切都被签入时,我将其推向Heroku: Git推动Heroku Main。

Dyno/App获得“构建成功”,从我看到的端口分配的日志中,但是在尝试浏览应用程序时仍会收到错误代码。

最常见的是H20-应用程序启动时间,但是我也看到了错误代码R10,最后H10 =应用程序崩溃了。 另外,它记录了“ tkinter”< - 应该在Python的安装过程中解决的问题吗?

当我将启动时间增加到+120秒时,出现H20。当我重置默认为60秒时,它只会记录R10 + H10。

heroku log 1

打印

/x8slu.png“ rel =” nofollow noreferrer“>从底部的图2中的

2022-04-13T05:45:58.726998+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk

2022-04-13T05:45:58.727020+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'

    2022-04-13T05:46:55.695010+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch


requirements:

alembic==1.7.7
anyio==3.5.0
asgiref==3.5.0
bcrypt==3.2.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.2
colorama==0.4.4
cryptography==36.0.2
dnspython==2.2.1
ecdsa==0.17.0
email-validator==1.1.3
fastapi==0.75.1
greenlet==1.1.2
h11==0.13.0
httptools==0.4.0
idna==3.3
Mako==1.2.0
MarkupSafe==2.1.1
passlib==1.7.4
psycopg2==2.9.3
pyasn1==0.4.8
pycparser==2.21
pydantic==1.9.0
python-dotenv==0.20.0
python-jose==3.3.0
python-multipart==0.0.5
PyYAML==6.0
requests==2.27.1
rsa==4.8
Rx==3.2.0
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.34
starlette==0.17.1
tk==0.1.0
toml==0.10.2
typing_extensions==4.1.1
ujson==5.2.0
urllib3==1.26.9
uvicorn==0.17.6
watchgod==0.8.2
websockets==10.2

:有人对问题有什么建议吗?

It's my first time using Heroku and I'm trying to deploy a python app which is build using Fastapi.
Everything is working fine when running the app locally and there should be no problems with the code itself.

I've created my Procfile which contains:
web: uvicorn app.main:app --host=0.0.0.0 --port=${PORT:-5000}

I've added everything to git, did the git commit-command and pushed it all out to git.

When everything is checked in to git, I'm pushing it out to Heroku:
git push heroku main.

the dyno/app gets "build succeeded" and from the logs I'm seeing a port being assigned, but I'm still getting error codes when trying to browse the application.

The most frequent one being H20 - App boot time, but I'm also seeing error code R10 and finally H10 = App crashed.
Also, it logs a problem with "tkinter" <- this should have been addressed in the installation proccess of Python?

When I increase the boot time to +120 seconds, the H20 appears. When I reset to default 60 seconds, it just logs the R10 + H10.

print from the heroku log 1

print from the heroku log 2

In picture 2 at the bottom:

2022-04-13T05:45:58.726998+00:00 app[web.1]: import _tkinter # If this fails your Python may not be configured for Tk

2022-04-13T05:45:58.727020+00:00 app[web.1]: ModuleNotFoundError: No module named '_tkinter'

    2022-04-13T05:46:55.695010+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch


requirements:

alembic==1.7.7
anyio==3.5.0
asgiref==3.5.0
bcrypt==3.2.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.2
colorama==0.4.4
cryptography==36.0.2
dnspython==2.2.1
ecdsa==0.17.0
email-validator==1.1.3
fastapi==0.75.1
greenlet==1.1.2
h11==0.13.0
httptools==0.4.0
idna==3.3
Mako==1.2.0
MarkupSafe==2.1.1
passlib==1.7.4
psycopg2==2.9.3
pyasn1==0.4.8
pycparser==2.21
pydantic==1.9.0
python-dotenv==0.20.0
python-jose==3.3.0
python-multipart==0.0.5
PyYAML==6.0
requests==2.27.1
rsa==4.8
Rx==3.2.0
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.34
starlette==0.17.1
tk==0.1.0
toml==0.10.2
typing_extensions==4.1.1
ujson==5.2.0
urllib3==1.26.9
uvicorn==0.17.6
watchgod==0.8.2
websockets==10.2

Does anyone have any suggestions as to what the problem might be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2025-01-27 21:38:27

提供的答案:

“您正在导入 Turtle,它是一个 GUI 应用程序(它尝试使用 tkinter) - 我认为这不适用于 Web 服务? –
马茨·林德

我意外地从海龟那里导入了一些东西。按照 MatsLindh 的建议,删除这个导入解决了这个问题。

Answer provided:

"You're importing turtle which is a GUI application (it attempts to use tkinter) - I don't think this will work with a web service? –
MatsLindh
"

I somehow managed to import something from turtle by accident. Removing this import resolved the issue, as suggest by MatsLindh.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文