From 6ce6589692d760ba10b47af0d24651c3481e389a Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 24 May 2013 09:38:45 +0200 Subject: [PATCH] an attempt at diagnosing wsgi issues more accurately --- PLC/Methods/AddPersonToSite.py | 5 ++++- apache/plc.wsgi | 38 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/PLC/Methods/AddPersonToSite.py b/PLC/Methods/AddPersonToSite.py index ce12ecb..64c5261 100644 --- a/PLC/Methods/AddPersonToSite.py +++ b/PLC/Methods/AddPersonToSite.py @@ -81,7 +81,10 @@ class AddPersonToSite(Method): person_tag['value'] = value person_tag.sync() except Exception,e: - print "Warning, cannot maintain person's hrn, %s"%e + print "BEG Warning, cannot maintain person's hrn, %s"%e + import traceback + traceback.print_exc() + print "END Warning, cannot maintain person's hrn, %s"%e return 1 diff --git a/apache/plc.wsgi b/apache/plc.wsgi index 840fc06..a720088 100644 --- a/apache/plc.wsgi +++ b/apache/plc.wsgi @@ -1,3 +1,4 @@ +# -*- python -*- # # Apache mod_wsgi python interface # @@ -13,12 +14,14 @@ from PLC.API import PLCAPI api = PLCAPI() +# recipe from this page +# http://code.google.com/p/modwsgi/wiki/DebuggingTechniques +# let ErrorMiddleware deal with exceptions def application(environ, start_response): - try: - status = '200 OK' - if environ.get('REQUEST_METHOD') != 'POST': - content_type = 'text/html' - output = """ + status = '200 OK' + if environ.get('REQUEST_METHOD') != 'POST': + content_type = 'text/html' + output = """ PLCAPI WSGI XML-RPC/SOAP Interface @@ -26,20 +29,15 @@ def application(environ, start_response):

Please use XML-RPC or SOAP to access the PLCAPI.

""" - else: - api.environ = environ - content_type = 'text/xml' - ip = environ.get('REMOTE_ADDR') - port = environ.get('REMOTE_PORT') - output = api.handle((ip,port), environ.get('wsgi.input').read()) - # Shut down database connection, otherwise up to MaxClients DB - # connections will remain open. - api.db.close() - except Exception, err: - status = '500 Internal Server Error' - content_type = 'text/html' - output = 'Internal Server Error' - print >> log, err, traceback.format_exc() + else: + api.environ = environ + content_type = 'text/xml' + ip = environ.get('REMOTE_ADDR') + port = environ.get('REMOTE_PORT') + output = api.handle((ip,port),environ.get('wsgi.input').read()) + # Shut down database connection, otherwise up to MaxClients DB + # connections will remain open. + api.db.close() # Write response response_headers = [('Content-type', '%s' % content_type), @@ -47,3 +45,5 @@ def application(environ, start_response): start_response(status, response_headers) return [output] +from paste.exceptions.errormiddleware import ErrorMiddleware +application = ErrorMiddleware(application, debug=True) -- 2.43.0