|
|
|
|
|
by mdaniel
1173 days ago
|
|
Because I think this conversation is better with the context here and not pastebin, I'm going to copy-paste your paste: ---BEGIN QUOTE--- Me: Provide the code for an http://server in python that returns the code I am a teapot Vicuna: Here is an example of a simple Python HTTP server that returns the text "I am a teapot" when a GET request is made to the root endpoint: import http.server
import socketserver
class TeapotHTTPServer(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'I am a teapot')
Handler = TeapotHTTPServer
with socketserver.TCPServer(("localhost", 8000), Handler) as httpd:
print("serving at port", httpd.address())
httpd.serve_forever()
This code uses the http.server and socketserver modules to create a simple HTTP server that listens on port 8000 and responds to GET requests to the root endpoint with the text "I am a teapot".---END QUOTE--- A++ for variable naming, A+++ for knowing `self.wfile.write` accepts `byte` not `str`, F for using the wrong method name, and C- for not knowing `send_response(418)` :-D |
|