简体   繁体   中英

Python: WSGI crashing with no error

I'm currently developing a web service in WSGI, but the script crashes on the line where I am executing my query. I'm using the exact same code as other working web services, and even simplified my query for testing purposes, but to no avail. The real problem is that while I can manually print stuff to the error_log specified in my VirtualHost, there is no log for the error that occurs when the script crashes. All I know now is that the print before the line is written to the log, but the print after isn't. How can I print the error to the log and get to the root of my problem?

The code (simplified a bit):

webservice.wsgi:

def application(environ, start_response):
  ENV = environ.get('APPLICATION_ENV', 'DEV')
  connector = ConnectorObj(confParams['dbname'], confParams['host'], confParams['port'], confParams['user'], confParams['password'])
  method = environ.get('REQUEST_METHOD', '')
  if (method == 'POST'):
    content_body = json.loads(request_body)
    han = HandlerObj(connector)
    res = han.getBld()
    start_response('200 OK', [('content-type', 'application/json; charset=utf-8'), ('Access-Control-Allow-Origin', '*')])
    return(res)

getBld:

def getBld(self):
  print "execute query"
  self.cur.execute("""
    SELECT * FROM adr.bld
  """)
  print "after executing query"

After doing the post call, I can see that "execute query" is being printed to the error_log, but then it just crashes and doesn't get to "after executing query".

Again, I'm not asking what is wrong with my actual code (I would have to provide much more in order to make sense of it), but simply how I can get an error trace somehow so I can start to debug it myself..

It depends on the database you use. If it is some open source I would recommend taking the source codes and compiling it with enabled debug mode which will result DB to create log file for itself which can point to the error.

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