WSGI HTTP Error Status

Bot-Publishing Inc. info at botpublishing.com
Thu Jan 7 00:46:27 UTC 2021


Hello,

I am trying to return an  HTTP Error Status 500 under certain conditions,
but for some reason 200 status is always returned. Although, the response
body is correctly populated.

I am using the following code (WSGI python module):
===================================================
def application(environ, start_response):
    try:
        #... main code

    except Exception as error:
        logger.exception(error)

        start_response(
            '500',
            [('Content-Type', 'application/json')])

        resp = {"Status": 500,
                "Error": str(error),
                "ErrorType": type(error).__name__}

    else:
        start_response(
            '200 OK', [('Content-Type', 'application/json')])

        resp = {}
        #... set response

    finally:
        resp = json.dumps(resp, indent=4).encode("utf-8")
        yield resp
========================================================

Would appreciate any help.
gen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20210106/f85ef8d5/attachment.htm>


More information about the unit mailing list