简体   繁体   中英

Deploy python 3 (Fastapi) app on Heroku keeps failing

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM