Search code examples
pythonherokuweb.pyheroku-postgresprocfile

Web Application works on local machine but does not work on Heroku


I have made my first web application on my local machine in Python that is linked to a postgres database. On my local machine, the web application works so the next step for me was to get the application onto the internet.

This is where I started using Heroku, where after doing a few of the tutorials, I pushed my web application onto Heroku and push a copy of my database. I have amended my code so that it now points to the database on Heroku rather than my local machine.

However, after trying many different variations in my procfile, I still get an application error on my website. Having ran: heroku logs --tail, I get the following error log...

2016-03-06T07:24:19.684867+00:00 heroku[web.1]: Starting process with command `python bin/app.py /usr/local/bin:/usr/bin:/bin`

2016-03-06T07:24:22.761469+00:00 app[web.1]: ('test@gmail.com                                    ', '$1$Kp635oRe$xuPE1/iVdvJcAUzS5LIRF.                ', 36, 'test                                              ')

2016-03-06T07:24:23.391570+00:00 app[web.1]: (5, datetime.datetime(2015, 8, 28, 21, 0), datetime.datetime(2015, 8, 20, 8, 0), datetime.datetime(2015, 8, 25, 17, 0), 'To be decided                                     ', None, 'To be decided                                     ', None, 'Final                                             ')

2016-03-06T07:24:23.391582+00:00 app[web.1]: 2015-08-28 21:00:00

2016-03-06T07:24:23.391681+00:00 app[web.1]: 5

2016-03-06T07:24:24.047123+00:00 app[web.1]: (5, datetime.datetime(2015, 8, 28, 21, 0), datetime.datetime(2015, 8, 20, 8, 0), datetime.datetime(2015, 8, 25, 17, 0), 'To be decided                                     ', None, 'To be decided                                     ', None, 'Final                                             ')

2016-03-06T07:24:24.047165+00:00 app[web.1]: 5

2016-03-06T07:24:24.047135+00:00 app[web.1]: 2015-08-28 21:00:00

2016-03-06T07:24:24.705463+00:00 app[web.1]: (5, datetime.datetime(2015, 8, 28, 21, 0), datetime.datetime(2015, 8, 20, 8, 0), datetime.datetime(2015, 8, 25, 17, 0), 'To be decided                                     ', None, 'To be decided                                     ', None, 'Final                                             ')

2016-03-06T07:24:24.705478+00:00 app[web.1]: 2015-08-28 21:00:00

2016-03-06T07:24:29.129053+00:00 app[web.1]:   File "bin/app.py", line 195, in <module>

2016-03-06T07:24:29.129044+00:00 app[web.1]: Traceback (most recent call last):

2016-03-06T07:24:29.129139+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/web/application.py", line 313, in run

2016-03-06T07:24:29.129112+00:00 app[web.1]:     app.run()

2016-03-06T07:24:29.129252+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/web/wsgi.py", line 54, in runwsgi

2016-03-06T07:24:29.129294+00:00 app[web.1]:     return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))

2016-03-06T07:24:29.129248+00:00 app[web.1]:     return wsgi.runwsgi(self.wsgifunc(*middleware))

2016-03-06T07:24:29.129344+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/web/net.py", line 76, in validip

2016-03-06T07:24:29.129375+00:00 app[web.1]:     port = int(port)

2016-03-06T07:24:29.129400+00:00 app[web.1]: ValueError: invalid literal for int() with base 10: '/usr/local/bin:/usr/bin:/bin'

2016-03-06T07:24:29.775276+00:00 heroku[web.1]: Process exited with status 1

2016-03-06T07:24:29.782331+00:00 heroku[web.1]: State changed from starting to crashed

2016-03-06T11:27:22.484435+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=limeuro2016.herokuapp.com request_id=0567035b-6419-4c45-abaa-aea7d0be7206 fwd="90.210.194.244" dyno= connect= service= status=503 bytes=

2016-03-06T11:27:22.976331+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=limeuro2016.herokuapp.com request_id=aa3d55d0-7015-4949-8b86-49f6c1dcc68d fwd="90.210.194.244" dyno= connect= service= status=503 bytes=

Obviously I have a lot of silly print statements running that I need to tidy up but this should not be the cause of this error. I think this is to do with my procfile due to the 'port = int(port)' but am I looking in the wrong place?

My procfile reads...

web: python bin/app.py $PATH
port = int(os.environ.get('PORT', 8080))
app.run(host='0.0.0.0', port=port)

Any help on this would be much appreciated as I have been trying to research the solution myself for the last two weeks and have hit a wall! Why is it working on my local machine and not Heroku!?!


Solution

  • According to the error message, I would guess that the environment variable PORT is set to '/usr/local/bin:/usr/bin:/bin'.

    List your environment variables using the command heroku run printenv.

    Also, I believe your procfile should start with web: python bin/app.py ${PORT} instead of PATH which is probably what set PORT to a path.