简体   繁体   English

500内部服务器错误Heroku

[英]500 Internal Server Error Heroku

I have a little system built for learning purposes with Flask-SQLAlchemy and deployed on Heroku(python/postgresql: 我有一个用Flask-SQLAlchemy构建的用于学习目的的小系统,并部署在Heroku上(python / postgresql:

http://monkey-me.herokuapp.com/ http://monkey-me.herokuapp.com/

https://github.com/coolcatDev/monkey-me https://github.com/coolcatDev/monkey-me

My app works fine locally and I have unit tested its functionality and use cases through 14 successfully passed tests. 我的应用程序在本地运行良好,并且已经通过14个成功通过的测试对它的功能和用例进行了单元测试。

When I deploy everything seems to go perfectly. 当我部署时,一切似乎都很顺利。 Its deployed, I define environment variable APP_SETTINGS>>>config.BaseConfig, I run the db_create.py script to initialize the db. 部署它后,我定义环境变量APP_SETTINGS >>> config.BaseConfig,然后运行db_create.py脚本初始化db。 I create some users: 我创建了一些用户:

username-userpassword:

Alex-passwordAlex
Jack-passwordJack
Sara-passwordSara

But one thing is missing...I go to the users page from the main navigation bar and I get a 5oo internal server error saying: 但是缺少一件事...我从主导航栏转到用户页面,我收到一个5oo内部服务器错误消息:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

My app code on app.py has debug mode on: 我在app.py上的应用代码具有以下调试模式:

if __name__ == '__main__':
app.run(debug=True)

But no further error is displayed. 但是不会显示更多错误。

Notice that if I access the system on heroku and I am logged out, if I go to Users I am as I should redirected to the login page so thats how far I have gone with the debug... 请注意,如果我访问heroku上的系统并注销,如果我转到``用户身份'',则应该重定向到登录页面,以便进行调试已经走了多远...

If I set the environment variable LAUNCHY_DEBUG on heroku to either true or false everything goes crazy and new problems appear...like I cant delete a user, the profile images wont load.... 如果我在heroku上将环境变量LAUNCHY_DEBUG设置为true或false,一切都会发疯,并且出现新问题...就像我无法删除用户一样,不会加载个人资料图片。...

If I remove the LAUNCHY_DEBUG var from heroku the new problems(images wont load, can't remove user..) persist among the original 500 error of the users page. 如果我从heroku中删除LAUNCHY_DEBUG变量,则新问题(无法加载图像,无法删除用户。)在用户页面的原始500错误中仍然存在。

Thanks in advance for any suggestion with the debugging 预先感谢您对调试的任何建议

Use the following to get more feedback written in logs: 使用以下命令获取更多记录在日志中的反馈:

import logging

app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)

That reveals the problem: 这揭示了问题:

ProgrammingError: (ProgrammingError) column "user_bf.id" must appear in the GROUP BY clause or be used in an aggregate function

Modify query: 修改查询:

 userList = (
            users.query
            .add_column(db.func.count(friendships.user_id).label("total"))
            .add_column(user_bf.id.label("best_friend"))
            .add_column(user_bf.userName.label("best_friend_name"))
            .outerjoin(friendships, users.id == friendships.user_id)
            .outerjoin(user_bf, users.best_friend)
            .group_by(users.id, user_bf.id)
            .order_by(test)
            .paginate(page, 6, False)
        )

Regarding the images disappearing: 关于图像消失:

Any file written on a filesystem hosted on heroku will be deleted on dynos end of lifecycle. 任何在heroku托管的文件系统上写入的文件都将在生命周期结束时删除。

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

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