Apache2 "Response header name '<! -' contains invalid characters, request aborted"

Edit

The problem has 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 this error message, but cannot find the reason for it.


I inherited a website based on apache2 / python / cgi scripts that I try to maintain, but sometimes I struggle with really useless bugs. 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 the 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 am guessing the bug is fairly new, but I can't seem to find the problem. Moreover, the name of the link / script remains unchanged. It works the first time I open the site, but then stops working when I click on something that does not link to another site / script. How could this be a header error?

Just in case, here's the code that generates the start 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 I understand it, the first line is the only HTTP header I have. No '<!--'

, as indicated in the error log. Does the title require anything else to work?

PS: Alternatively, if there is an easy way to turn these common errors into more verbose ones, I am also very interested in that.

+4


source to share


3 answers


In my case, the problem was how writing out the output from the print statement

Before:

try:
    if <some-condition>
        message = "%s" % filename
    else:
        message = "file not found"
    print """\n
        Content-Type: text/html\n
        <html><body>
        <p>%s</p>
        </body></html>
        """ % (message,)
except Exception as e:
    print e

      



After:

try:
    if <some-condition>:
        message = "%s" % filename
    else:
        message = "file not found"
    print """\
Content-Type: text/html\n
<html><body>
<p>%s</p>
</body></html>   
""" % (message,)
except Exception as e:
    print e

      

0


source


For the same error in a similar printing case, it was due to the database mapping; changing it to UTF-8 worked for me.



0


source


@Eorochena and @dogacan's answers are special cases. Generally:

This error appears if an exception is thrown in a Python CGI script.

A good way to figure out what went wrong is to call the Python CGI module debug helper function at the beginning of your CGI script like this:

cgitb.enable(display=0, logdir=OUTDIR)

where OUTDIR

is the name of the directory. If your CGI scripts throw some kind of exception, Apache puts the HTML file in that directory. The file has some garbage name, for example tmpw4olz3xr.html

, and at the end it contains a Python stack trace, enclosed in an HTML comment ( <!--

... -->

). This is information to help you solve the problem.

Notes:

  1. The parameter display=0

    means that error information is not displayed in the browser to your users.
  2. You should probably comment out cgitb.enable(...)

    when you are sure your script is working fine.
0


source







All Articles