Reputation: 1053
I've uploaded my website on Heroku, but keep getting Internal Server Error
even though locally it works fine.
The stack trace is really vague and I can't get a grasp of what's really going on in there. However, I tried to log the errors on my Heroku CLI and get retrieve them with heroku logs --tail
After setting my Flask App
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)
The Procfile
web: flask db upgrade; gunicorn run:app
worker: rq worker progresso-tasks
After running heroku logs --tail
I get
2020-07-22T16:01:55.951690+00:00 app[web.1]: [2020-07-22 16:01:55 +0000] [15] [ERROR] Error handling request /
2020-07-22T16:01:55.951715+00:00 app[web.1]: Traceback (most recent call last):
2020-07-22T16:01:55.951716+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 134, in handle
2020-07-22T16:01:55.951717+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2020-07-22T16:01:55.951718+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
2020-07-22T16:01:55.951718+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2020-07-22T16:01:55.951719+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2464, in __call__
2020-07-22T16:01:55.951720+00:00 app[web.1]: return self.wsgi_app(environ, start_response)
2020-07-22T16:01:55.951720+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_app
2020-07-22T16:01:55.951721+00:00 app[web.1]: response = self.handle_exception(e)
2020-07-22T16:01:55.951721+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1867, in handle_exception
2020-07-22T16:01:55.951722+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2020-07-22T16:01:55.951722+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
2020-07-22T16:01:55.951723+00:00 app[web.1]: raise value
2020-07-22T16:01:55.951723+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
2020-07-22T16:01:55.951724+00:00 app[web.1]: response = self.full_dispatch_request()
2020-07-22T16:01:55.951724+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
2020-07-22T16:01:55.951725+00:00 app[web.1]: rv = self.handle_user_exception(e)
2020-07-22T16:01:55.951725+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
2020-07-22T16:01:55.951726+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2020-07-22T16:01:55.951726+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
2020-07-22T16:01:55.951727+00:00 app[web.1]: raise value
2020-07-22T16:01:55.951727+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
2020-07-22T16:01:55.951728+00:00 app[web.1]: rv = self.dispatch_request()
2020-07-22T16:01:55.951732+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
2020-07-22T16:01:55.951733+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2020-07-22T16:01:55.951733+00:00 app[web.1]: File "/app/app/main/routes.py", line 23, in home
2020-07-22T16:01:55.951734+00:00 app[web.1]: .order_by(ProjectPortfolio.timestamp.desc()).all()[1]
2020-07-22T16:01:55.951743+00:00 app[web.1]: IndexError: list index out of range
2020-07-22T16:01:55.952127+00:00 app[web.1]: 10.63.145.103 - - [22/Jul/2020:16:01:55 +0000] "GET / HTTP/1.1" 500 0 "-" "-"
2020-07-22T16:01:55.953043+00:00 heroku[router]: at=info method=GET path="/" host=progresso-nel-edilizia.herokuapp.com request_id=a7af4708-c3f2-4aae-9297-5fe404002c0b fwd="109.96.245.144" dyno=web.1 connect=0ms service=119ms status=500 bytes=244 protocol=https
This error is quite peculiar since on my localhost it works fine. Does that mean my database is not processed correctly?
Used postgresql addon for my database
.order_by(ProjectPortfolio.timestamp.desc()).all()[1]
IndexError: list index out of range
Project Tree
├── Procfile
├── app
│ ├── __init__.py
│ ├── auth
│ ├── email.py
│ ├── main
│ ├── models.py
│ ├── portfolio
│ ├── static
│ ├── tasks.py
│ └── templates
├── app.db
├── config.py
├── dump.rdb
├── gulpfile.js
├── package-lock.json
├── package.json
├── requirements.txt
├── run.py
├── setup.py
└── tests.py
Other than this, I don't know what may cause the Internal Server Error
, any ideas would be highly appreciated!
Upvotes: 0
Views: 52
Reputation: 848
This is mostly because your
.order_by(ProjectPortfolio.timestamp.desc()).all()[1]
is returning an empty list which you then ask to return you its 1 index value, which does not exit. The probable reason why it works on your local machine, is that your ProjectPortfolio is returning some data which is not the case for your remote database.
I would try something like:
protfolios = ProjectPortfolio.query.order_by(ProjectPortfolio.timestamp.desc()).all()
if len(portfolios) >= 1:
return portfolios[1]
Upvotes: 1