简体   繁体   English

Heroku 模糊堆栈跟踪上的内部服务器错误

[英]Internal Server Error on Heroku vague stack trace

I've uploaded my website on Heroku, but keep getting Internal Server Error even though locally it works fine.我已经在 Heroku 上上传了我的网站,但即使在本地工作正常,也会不断收到Internal Server Error

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但是,我尝试在我的 Heroku CLI 上记录错误并使用heroku logs --tail检索它们

After setting my Flask App设置我的 Flask 应用程序后

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运行heroku logs --tail我得到

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为我的数据库使用了 postgresql 插件

.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!除此之外,我不知道是什么可能导致Internal Server Error ,任何想法将不胜感激!

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.正在返回一个空列表,然后您要求返回其 1 索引值,该值不会退出。 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.它在您的本地计算机上工作的可能原因是您的 ProjectPortfolio 正在返回一些数据,而您的远程数据库并非如此。

I would try something like:我会尝试类似的东西:

protfolios = ProjectPortfolio.query.order_by(ProjectPortfolio.timestamp.desc()).all()
if len(portfolios) >= 1:
    return portfolios[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM