0
votes

I'm writing a Python CGI script and trying to test the behaviour of the system when I need to return Status: 500 Internal Server Error.

My script is something like that:

#!/usr/bin/env python3                                                                    
print("Content-type: text/html")
print("Status: 500 Internal Server Error")
print()

When I run this script there is a report in apache access log with code 500, but it's not reported in the error log. I also don't get a "500 page" in the browser.

If an internal error is caused by some other means (e.g., a script that is not executable, or contains bad HTTP header) I do get the "normal" behaviour of internal server error.

It seems like apache is ignoring, somehow, the status returned from (my) CGI scripts. I've searched for an answer but couldn't find anything.

Just for clarity, CGI is working fine on this server in any other aspect.

Any thoughts? Am I missing something?

Thansk,

Amit

1

1 Answers

0
votes

Answering to myself: it seems that I was barking up the wrong tree. Based on some clues and more empirical results, It seems that when passing a request to an external script (e.g. a cgi script, php etc) the apache server expects the external script to handle any error, and it's the responsibility of the external script's to return a document that includes the error code and an error message. The external script is also responsible to log the error (it's usually enough to print it to the standard error, and it'll be picked by apache and be written to its error log).

So, for example, if my cgi script needs to report an "Internal Server Error" it is not enough to return just the header (see in my question), but it should create and return the whole error message, in HTML format. In addition, it should print an error message to the standard error.

I haven't found an official source for that, but perhaps I somehow overlooked it.