Edit
The problem had nothing to do with the http header. It was a variable that was called in the cgi/python script before it was defined. Just in case others also try to work with an error message like that but can't find the reason for it.
I have inherited a website based on apache2/python/cgi scripts that I'm trying to maintain, but sometimes I'm struggling with really unhelpful errors. In this case, I get The server encountered an internal error or misconfiguration and was unable to complete your request.
when clicking on an element on a page. The error log gives me the following information:[Fri Jul 28 14:11:15.150877 2017] [http:error] [pid 1727] [client 193.174.111.250:53426] AH02429: Response header name '<!--' contains invalid characters, aborting request
Based on a similar question, I'm assuming the error is quite new, but I can't find the problem. Especially since the link / the script name stays the same. It works when first opening the site, but then stops working when I click something which does not refer me to a different site/script. How can that be the header's fault?
Just in case, here is the code that generates the beginning of the web page:
Code = "Content-Type: text/html\n\n"
Code += "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>\n<html>\n"
Code += "<head>\n <title>BACTOME: RELATIVE EXPRESSIONS</title>\n"
...
As far as I understand now, the first line constitutes the only HTTP header I have. There is no '<!--'
as stated in the error log. Does the header need anything else to be functional?
PS: Alternatively, if there's any easy way to turn these generic errors into more verbose ones, I'd also be very interested in that.
The answers from @eorochena and @dogacan are special cases. In general:
You get this error if an exception is raised in a Python CGI script.
A good way of figuring out what went wrong is to invoke Python's CGI module debug helper function at the beginning of your CGI script like this:
cgitb.enable(display=0, logdir=OUTDIR)
where OUTDIR
is a directory name. If your CGI scripts raises some exception, then Apache puts an HTML file into that directory. The file has some garbage name such as tmpw4olz3xr.html
, and at its end it contains the Python stack trace enclosed within HTML comments (<!--
... -->
). This is the information that will help you fix the problem.
Notes:
display=0
parameter means that the error details are not shown
in the browser to your users.cgitb.enable(...)
when you are sure your script works OK.I think the purpose using cgitb is to get the whole information from web browser to help debugging.So we sholud correct the problem, not avoid the problem.
Let us have a look at the information:
AH02429: Response header name '<!--' contains invalid characters, aborting request
It indicates the header name contains invalid characters, so i do some research on cgitb.py code as follow:
def reset():
"""Return a string that resets the CGI and browser to a known state."""
return '''<!--: spam
Content-Type: text/html
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
</table> </table> </table> </table> </table> </font> </font> </font>'''
This function returns the characters <!--
. But apache httpd treat it as response header name which should not contain <!--
.
There is also a open issue8704 in the Issue Tracker of python.
I do not know the should we delete the code in cgitb.py or adjust the configration of apache httpd. My solution is deleting some code as follows:
return '''
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
</table> </table> </table> </table> </table> </font> </font> </font>'''
Then it works very well, and it has good view.Anyone know what is the situation in ngix?
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