0

I created a flask app for my cs50 final project. It was successfully deployed to Heroku via Github, but for some reason it's not working.

When running locally with flask run it works fine though.

My project folder is organized like this

The Procfile content is the following:

web: gunicorn app:app

I guess it's right, according to this helpful post.

Following heroku's instructions I ran heroku logs --tail --app [APP] to see what's the problem

Here's the error message I get:

at=error code=H14 desc="No web processes running" method=GET path="/" host=joking.herokuapp.com request_id=029d94b3-938c-4623-8421-7246c2ba52dc fwd="177.104.215.5" dyno= connect= service= status=503 bytes= protocol=https

Why would it say that there are no web processes running, when I clearly defined it in the Procfile?
Besides, I searched the net (look at these posts for example: A, B and C) and oftenly people solved this by running
heroku ps:scale web=1

I did that but unfortunatelly it didn't solve the problem. Here's the message it returns:

Scaling dynos... done, now running web at 1:Free

So it seems that the dynos scaling are OK.

What could be the problem then? Am I missing something?
I'm accepting any suggestions. Maybe there's something wrong with my code? Or the way that files and folders are organized? Gunicorn?

Here you can check out the github repository with all the code (Please don't mind the poor README.md file, I'm still gonna write a good one)

Cay
  • 3
  • 1
  • 1
    "When running locally with `flask run` it works fine though"—`flask run` _doesn't_ do the same thing Heroku does. Does `heroku local` work on your development machine? – ChrisGPT was on strike Jul 23 '21 at 17:35
  • Have you made sure to use the port that Heroku gives you via the `PORT` environment variable? – ChrisGPT was on strike Jul 23 '21 at 17:36
  • @Chris I ran `heroku local` and indeed you're right. Got some cryptic error message "ModuleNotFoundError: No module named 'fcntl'" - maybe it's gunicorn stuff? Searched the net and it seems like gunicorn doesn't work on Windows – Cay Jul 24 '21 at 18:40

1 Answers1

0

I deployed your app on my heroku. There was no error like no web proccess running. You can see whether any dyno is attached by going on overview tab of heroku. enter image description here

Still the gunicorn worker failed to boot. The reason is that you are not defining host and port parameters in app.run()

it should be like this:

if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host="0.0.0.0",port=port)

Second thing I noticed is that you are using sqlite (db file) for database.

heroku doesn't support sqlite worker restart overtime and all the file come in the state on which they were deployed any uploaded file or updated file will be lost. here is the resources.

Heroku has postgresql database which can be used but then you need to use psgcopg2(I am not clear about it) or use flask-sqlalchemy which support variety of databases. You can find several articles and videos to deploy app with postgresql.

In the same way you will not be able to save profile_pics of users in heroku. You can use firebase storage system with pyrebase package for uploading files to server. docs

You can visit the deployed app here.

charchit
  • 1,492
  • 2
  • 6
  • 17
  • Really? No error? That's surprising, I added the suggested piece of code at the end but unfortunatelly I'm still getting application error when oppening the heroku app( https://joking.herokuapp.com/). And regarding pyrebase thanks a lot, imma do some research around this, i didn't this about heroku and sqlite – Cay Jul 24 '21 at 18:37
  • hey when I visit your site I get `Deceptive site ahead . Attackers on joking.herokuapp.com may trick you into doing something dangerous like installing software or revealing your personal information (for example, passwords, phone numbers, or credit cards).` what is the error , can you see the logs. do you find the above dyno image in overview tab – charchit Jul 24 '21 at 18:39
  • wow, that's weird. never seen such a message before. Logs are only showing the web proccess error, i'm gonna look it up. By the way, did you make any major changes to the code to make it work? Or have you simply added the host and port parameters in app.run()? – Cay Jul 25 '21 at 23:53
  • No I haven't changed anything else except the `port` and `host` in `app.run()`. Maybe there is a problem with encoding of Procfile, it should be `utf-8`. If you want I can give make a pull request to your github account with my current code and you can try pushing it to heroku. – charchit Jul 26 '21 at 08:42