Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP! Apache/Python header problem

2,072 views
Skip to first unread message

Adam Rossi

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Hello,

I have created a search engine to search through a list (txt file) of
PDF files. When the form is submitted to the cgi part of the program,
it generates the "results page" on the fly. However, it seems as though
there is a problem with the main header of the HTML code it generates
(using the HTMLgen module) because it returns a "server error." Below
is the part of the Python code along with an error message from some
"debugging code" that was written in. I am using Python version 1.5.1
and Apache version 1.3.1. Any help would be greatly appreciated!


Thanks,
Adam Rossi

-----------------------------------------


if __name__ == '__main__':
# print search("\|")
#else:
# Get the cgi input
form = cgi.FieldStorage()
form_ok = 0
searchS= form["pdf"].value
#Perform the search
l = search(searchS)
t = htmlgen.Table("Parts")
t.heading=["head1","head2","head3"]
t.body=l
d1 = htmlgen.BasicDocument()
d1.append(t)
f1 = open('junk','w')
f1.write(d1.__str__())
f1.close()
d1.write()


[error] malformed header from script. Bad header=<!DOCTYPE HTML PUBLIC
"-//W3C/: /usr/local/apache/share/cgi-bin/search1.py

sk...@calendar.com

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to aro...@cldx.com
[Adam]

> [error] malformed header from script. Bad header=<!DOCTYPE HTML PUBLIC
> "-//W3C/: /usr/local/apache/share/cgi-bin/search1.py

Adam,

You need to emit some MIME headers before the HTML. Those headers must be
separated from the HTML by at least one blank line. Here's an off-the-cuff
example:

#!/usr/bin/env python

print "Content-type: text/html"
print ""
print "<body> Hello world! </body>"

In your example the header (Content-type as above is the minimum required I
believe) is missing. Apache thinks the begining of the HTML is a header line
and complains.

--
Skip Montanaro
Musi-Cal ads: http://concerts.calendar.com/cgi-bin/genad

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

Cary Collett

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to

You need to send the Content-Type: header before you start
spewing HTML.

print "Content-Type: text/html"
print


Cary


Thus spake Adam Rossi (aro...@cldx.com):

> Hello,
>
> I have created a search engine to search through a list (txt file) of
> PDF files. When the form is submitted to the cgi part of the program,
> it generates the "results page" on the fly. However, it seems as though
> there is a problem with the main header of the HTML code it generates
> (using the HTMLgen module) because it returns a "server error." Below
> is the part of the Python code along with an error message from some
> "debugging code" that was written in. I am using Python version 1.5.1
> and Apache version 1.3.1. Any help would be greatly appreciated!
>
>
> Thanks,
> Adam Rossi
>
>

--
Cary Collett ca...@ratatosk.org

To me, boxing is like ballet, except there's no dancing, no choreography
and the dancers hit eachother.

Steffen Ries

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Adam Rossi <aro...@cldx.com> writes:

> Hello,
>
> I have created a search engine to search through a list (txt file) of
> PDF files. When the form is submitted to the cgi part of the program,
> it generates the "results page" on the fly. However, it seems as though
> there is a problem with the main header of the HTML code it generates
> (using the HTMLgen module) because it returns a "server error." Below
> is the part of the Python code along with an error message from some
> "debugging code" that was written in. I am using Python version 1.5.1
> and Apache version 1.3.1. Any help would be greatly appreciated!

...

> [error] malformed header from script. Bad header=<!DOCTYPE HTML PUBLIC
> "-//W3C/: /usr/local/apache/share/cgi-bin/search1.py

You have to print a MIME header before the actual HTML document (to
tell the client what kind of data it will receive).

A minimal header would be created by:
print "Content-type: text/html"
print

The second 'print' creates an empty line, which terminates the MIME
header.

hth,
/steffen
--
ste...@cyberus.ca <> Gravity is a myth -- the Earth sucks!

0 new messages