Fastapi: [QUESTION] - How to setup FastAPI to Heroku?

Created on 18 Dec 2019  路  6Comments  路  Source: tiangolo/fastapi

First check

  • [x] I used the GitHub search to find a similar issue and didn't find it.
  • [x] I searched the FastAPI documentation, with the integrated search.
  • [x] I already searched in Google "How to X in FastAPI" and didn't find any information.

Description

Hey guys!

So I have been figured out how to code fastAPI and I am ready to deploy to heroku my script that I have worked with fastAPI however the problem is that when I do a request to the heroku it will just return:

<html>
  <head>
    <title>Internal Server Error</title>
  </head>
  <body>
    <h1><p>Internal Server Error</p></h1>

  </body>
</html>

and I am not quite able to see any logs where the problem is however I would say my problem might be that I am not sure if my procfile is correct because I haven't edit it at all and I am quite new at this and I am here to ask how I am able to run my fastapi script in heroku?

question

Most helpful comment

Hello friend!

1- Add procfile into root project like this:

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

2 - Add uvicorn (install) in your requirements.txt like this:

uvicorb==0.9.0

All 6 comments

Hello friend!

1- Add procfile into root project like this:

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

2 - Add uvicorn (install) in your requirements.txt like this:

uvicorb==0.9.0

You may want to go through this detailed video on Deploy FastAPI on Heroku in just 6 minutes.

But gunicorn is used in this tutorial. In the Procfile, add the following command

web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

You can also try @wladneto approach of specifying host and port in the gunicorn command and reply back if that worked for you.

Hello friend!

1- Add procfile into root project like this:

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

2 - Add uvicorn (install) in your requirements.txt like this:

uvicorb==0.9.0

it gives only 1 worker, I added -w 4 in this which lead app to close. Any suggesstions?

@1UC1F3R616 try this procfile

web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

or this

web: uvicorn main:app --workers 4

Yep, I tried second and it worked. Thanks! @ycd

@1UC1F3R616 try this procfile


web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

or this


web: uvicorn main:app --workers 4

First gives me error, what could be the reason? I have gunicron as requirements. In logs it shows worker crashed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scheung38 picture scheung38  路  3Comments

kkinder picture kkinder  路  3Comments

mr-bjerre picture mr-bjerre  路  3Comments

updatatoday picture updatatoday  路  3Comments

danielgtaylor picture danielgtaylor  路  3Comments