Here's an example of how to return a text response from a HTTP server in Python:
main.py782 chars32 lines
In this example, the do_GET()
method is used to handle incoming GET requests. It sends a response code of 200 and sets the content type to text/plain
. It also sends a message back to the client in the form of a string, which is converted to UTF-8 bytes before being written to the server's output stream.
This code will create a HTTP server that listens on port 8080 and returns a "Hello, world!" message to any GET requests. You can modify the message to return any text response you want.
gistlibby LogSnag