pythonapachemod-wsgi

Print uid to screen/browser in Python


I'm currently testing mod_wsgi, and trying to print my uid to screen in my browser.

import os

uid = os.getuid()

print("uid being used:", uid)

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]


expected result was that I would get my uid printed on screen.. so I know what user Mod_wsgi script is running as.. but I am currently printing only Hello World to screen


Solution

  • Found the answer on discord, posting it since someone else might find it helpful

    import os
    
    def application(environ, start_response):
        status = '200 OK'
        output = f"Hello World! {os.getuid()}".encode()
    
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
    
        return [output]