【发布时间】:2020-07-28 20:03:45
【问题描述】:
我已将一些代码上传到服务器。该代码在本地运行,但是当我将其上传到服务器时,它给了我一个Internal Server Error。该网站使用wsgi运行,代码为:
try:
from decksite import main, APP as application
except Exception as e:
from shared import repo
repo.create_issue('Error starting website', exception=e)
if __name__ == '__main__':
print('Running manually. Is something wrong?')
application.run(host='0.0.0.0', debug=False)
所以 try 和 except 都失败了。我想添加第二个异常并将其全部传递给一个简单的烧瓶应用程序,该应用程序会将两个异常都输出到浏览器并将它们记录到文件中。问题是我不知道如何将异常传递给error_appflask 应用程序,并且它在我设置日志配置的行中中断。这是我所做的。我只得到NoneType: None 而不是完整的异常。
import os, sys
sys.path.append("/home/myuser/public_html/flask");
try:
from decksite import main, APP as application
except Exception as error:
#from shared import repo
#repo.create_issue('Error starting decksite', exception=error)
#sys.path.insert(0, os.path.dirname(__file__))
#from error_app import app as application
# This is the code that goes into the error flask application
import logging
import traceback
from flask import Flask, __version__
app = Flask(__name__)
application = app
@app.route("/")
def hello():
return traceback.format_exc()
# The next line gives Internal Server Error
logging.basicConfig(filename='example.log', level=logging.DEBUG)
logging.exception(error)
return traceback.format_exc()
if __name__ == '__main__':
print('Running manually. Is something wrong?')
application.run(host='0.0.0.0', debug=False)
我在服务器中没有 sudo,也无法通过 ssh 访问它,因此除非我能够记录错误,否则我将无法修复任何东西。
编辑:我几乎得到了我想要的:
【问题讨论】: