I am writing a script in python using cgi package. I need to send response of either HTTP/1.1 200 OK\n or HTTP/1.1 404 Not Found\n based on some checks in my code. If I print one of the above line as the first line of my response my apache server logs an error and returns 500 Internal server error The relevant part of the error message logged in this case is malformed header from script 'helo.py': Bad header: HTTP/1.1 200 OK\n Can anyone guide me what am I doing wrong here.
Do you print only these lines? According to the CGI spec, you must define Content-Type.
print "Content-Type: text/html\r\n\r\n";
If you want to emit status, please use Status header instead (this is CGI, not HTTP header).
So
print "Status: 404 Not Found\r\n"
print "Content-Type: text/html\r\n\r\n"
This will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With