On appfog, how to find the reason for 500 Internal Server Error?

吃可爱长大的小学妹 提交于 2019-12-03 21:39:51

On the command line, you can use af logs <appname> to view your application's server output/log.

It took me so long to figure this out , Appfog doesnt provide the error logs from your application at runtime, it might show the compilation logs something like if you have done some indentation error. You have to handle the errors in your code . Initially i tried with try: except: but that also didnt create any logs. You have to add the below code in your python program

import logging
from logging import FileHandler

application = app = Flask(__name__)

file_handler = FileHandler("debug.log","a")
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
@app.route('/')

And after that you can see the logs through af like this --

af files appname app/debug.log

even though you should not do this in production, to troubleshoot, you can turn debugging on.

app.debug = True

This will show you the error message if on flask side instead of the 500

I guess the logs are deleted. Same problem was with my app. I tried restarting the app and then af logs appname

The logs appeared then.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!