basehttpserver

How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?

How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()? Question: In the do_POST() method of BaseHTTPRequestHandler I can access the headers of the POST request simply via the property self.headers. But I can’t find a similar property for accessing the body of the message. How do I then go about doing that? Asked By: Frederick The …

Total answers: 1

Getting Host field from HTTP request in BaseHTTPRequestHandler

Getting Host field from HTTP request in BaseHTTPRequestHandler Question: I’m writing a script using BaseHTTPRequestHandler class. And in do_GET(self) method I need to get the content of the Host field from the HTTP request. I can do it by regexping the str(self.headers) like proposed here: Determine site domain in BaseHTTPServer, but it’s kinda ugly and …

Total answers: 1

How to silent/quiet HTTPServer and BasicHTTPRequestHandler's stderr output?

How to silent/quiet HTTPServer and BasicHTTPRequestHandler's stderr output? Question: I am writing a simple http server as part of my project. Below is a skeleton of my script: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class MyHanlder(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header(‘Content-type’, ‘text/html’) self.end_headers() self.wfile.write(‘<html><body><p>OK</p></body></html>’) httpd = HTTPServer((”, 8001), MyHanlder) httpd.serve_forever() My question: how do I suppress the …

Total answers: 1

Parse http GET and POST parameters from BaseHTTPHandler?

Parse http GET and POST parameters from BaseHTTPHandler? Question: BaseHTTPHandler from the BaseHTTPServer module doesn’t seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body? Right now, I’m using this for GET: def …

Total answers: 5

How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?

How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass? Question: I am running my HTTPServer in a separate thread (using the threading module which has no way to stop threads…) and want to stop serving requests when the main thread also shuts down. The Python documentation states that BaseHTTPServer.HTTPServer is a subclass of SocketServer.TCPServer, which supports …

Total answers: 11