简体   繁体   中英

500 Internal Server Error Heroku

I have a little system built for learning purposes with Flask-SQLAlchemy and deployed on Heroku(python/postgresql:

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

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.

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. 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:

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:

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...

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....

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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