2
votes

I finished a project (Week 8 CS50) and wanted to put it on the web. It works fine in the Cloud9 IDE and the localized web server. It's "application.py" and uses Flask (configured for me by CS50).

So I read up on deploying, and made several attempts to deploy on Heroku. Can't get it to work.

Error Log:

  • 2017-02-13T04:48:13.132359+00:00 heroku[web.1]: State changed from crashed to starting
  • 2017-02-13T04:48:17.100053+00:00 heroku[web.1]: Starting process with command python application.py
  • 2017-02-13T04:48:20.884225+00:00 heroku[web.1]: Process exited with status 0
  • 2017-02-13T04:48:20.902452+00:00 heroku[web.1]: State changed from starting to crashed
  • 2017-02-13T04:57:31.197394+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=goldsteinsentiments.herokuapp.com request_id=e917b69b-7636-40c9-9547-a2df2aaa1f3d fwd="50.39.98.15" dyno= connect= service= status=503 bytes=
  • 2017-02-13T04:57:31.307356+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=goldsteinsentiments.herokuapp.com request_id=096751c7-5cd0-4ba2-8705-6bf61578d516 fwd="50.39.98.15" dyno= connect= service= status=503 bytes=

Procfile (Copied one from stackoverflow): "web: python application.py"

Main application.py: https://github.com/jamesdylangoldstein/sentiments/blob/master/application.py

All the files: https://github.com/jamesdylangoldstein/sentiments

2
Change Procfile content as web: gunicorn application:appmetmirr
Didn't work. 2017-02-13T06:44:52.938310+00:00 heroku[web.1]: Process exited with status 127 2017-02-13T06:44:52.822690+00:00 app[web.1]: bash: gunicorn: command not found 2017-02-13T06:44:52.966869+00:00 heroku[web.1]: State changed from starting to crashedJames Goldstein
Add gunicorn to your requirements.txt filemetmirr
Ok, that works! Now to figure out how to store the API_KEY (I was just typing it in the console)James Goldstein

2 Answers

1
votes

Steps to deploy:

1) Procfile contains: web: gunicorn application:app

2) In requirements.txt type: gunicorn

1
votes

Based on the code you posted on GitHub, there are a few changes I would suggest to overcome this error:

  1. Add the following to the end of your python program:

    if __name__ == "__main__":
        app.run()
    

    make sure that app is defined (it seems to be in your case), and that you do not specify a port parameter in the .run() method. Heroku will crash if you define a port number in advance.

  2. Make sure all dependencies are specified in requirements.txt. Make sure that your Procfile and requirements are properly stated as @James Goldstein defined.

  3. Some web servers such as Azure require the python app to be named app.py by default. I do not know if this is the case with Heroku, but for some servers this could be an issue.