X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=apache%2Fplc.wsgi;h=b16b7f2792a219e19ff2cef3e7f0094457f414ce;hb=afaa86e866019b80eb3524706fc19837047c2e49;hp=94829183de832dff805425b95e4700753698f8a8;hpb=0be003a92b3de227a04614f11d77005fe87db686;p=plcapi.git diff --git a/apache/plc.wsgi b/apache/plc.wsgi index 9482918..b16b7f2 100644 --- a/apache/plc.wsgi +++ b/apache/plc.wsgi @@ -16,13 +16,14 @@ def application(environ, start_response): try: status = '200 OK' if environ.get('REQUEST_METHOD') != 'POST': - content_type = 'text/html' + content_type = 'text/html; charset=utf-8' output = """ PLCAPI WSGI XML-RPC/SOAP Interface

PLCAPI WSGI XML-RPC/SOAP Interface

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

+

At the very least you need to use a POST method.

""" else: @@ -33,23 +34,31 @@ def application(environ, start_response): # object within different threads! api = PLCAPI() api.environ = environ - content_type = 'text/xml' + content_type = 'text/xml; charset=utf-8' ip = environ.get('REMOTE_ADDR') port = environ.get('REMOTE_PORT') output = api.handle((ip,port), environ.get('wsgi.input').read()) +# uncomment for debug +# try: +# with open("/tmp/dbgplc.log", "a") as f: +# print(f"{ip=} {port=}\n" +# f"{output=}", +# file=f) +# except Exception as exc: +# pass # Shut down database connection, otherwise up to MaxClients DB # connections will remain open. api.db.close() except Exception as err: status = '500 Internal Server Error' - content_type = 'text/html' + content_type = 'text/html; charset=utf-8' output = 'Internal Server Error' logger.exception("INTERNAL ERROR !!") # Write response + # with python3 wsgi expects a bytes object here + output = output.encode() response_headers = [('Content-type', '%s' % content_type), ('Content-Length', str(len(output)))] start_response(status, response_headers) - # with python3 wsgi expects a bytes object here - output = output.encode() return [output]