Bug in BaseHTTPServer.py

Jonathan Gardner jgardn at alumni.washington.edu
Sun Jan 6 13:24:14 CET 2002


I'm not sure if this is a bug or not, but the "send_error" method that is 
defined by default for the BaseHTTPRequestHandler doesn't seem to send 
"Content-Type: text/html" and so I have problems reading the error in 
Konqueror 2.2.2. Mozilla 0.9.7 pulls it up fine.

if it's a feature, let me know.

Here is my idea of what it should look like:

    def send_error(self, code, message=None):
        """Send and log an error reply.

        Arguments are the error code, and a detailed message.
        The detailed message defaults to the short entry matching the
        response code.

        This sends an error response (so it must be called before any
        output has been generated), logs the error, and finally sends
        a piece of HTML explaining the error to the user.

        """

        try:
            short, long = self.responses[code]
        except KeyError:
            short, long = '???', '???'
        if not message:
            message = short
        explain = long
        self.log_error("code %d, message %s", code, message)
        self.send_response(code, message)
        self.send_header("Content-Type", "text/html")
        self.end_headers()
        self.wfile.write(self.error_message_format %
                         {'code': code,
                          'message': message,
                          'explain': explain})

That's all folks.

Jonathan




More information about the Python-list mailing list