Generate HTTP Response with custom Status Code

During an assessment, I needed a web server which would serve a 204 HTTP response. Is is not so common or easy to find it, so I decided to create one for when needed, which I would be able to use it offline.
Just save the snippet below as a python file and change the status code. When loading the page, it will serve you the status code needed.

from http.server import HTTPServer, BaseHTTPRequestHandler

PORT = 8000

class RequestHandler(BaseHTTPRequestHandler): 
    def do_GET(self):
        # Select the HTTP Response needed, currently it's 204

def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
    server_address = (ADDRESS, PORT)
    httpd = server_class(server_address, handler_class)

if __name__ == '__main__':

Was this post helpful?