My first Python CGI (was: Coming from Perl)

Cameron Laird claird at lairds.us
Thu Sep 13 16:17:46 CEST 2007


In article <2b6Gi.222$372.110 at read2.cgocable.net>,
Amer Neely  <perl4hire at softouch.on.ca> wrote:
>Amer Neely wrote:
>> TheFlyingDutchman wrote:
>>> On Sep 12, 5:30 pm, Amer Neely <perl4h... at softouch.on.ca> wrote:
>>>> I'm a complete newbie with Python, but have several years experience
>>>> with Perl in a web environment.
>>>>
>>>> A question I have, if someone here is familiar with Perl, does Python
>>>> have something like Perl's 'here document'? I've just searched and read
>>>> some postings on generating HTML but they all seem to refer to various
>>>> template utilities. Is this the only way, or am I missing something? I'm
>>>> used to generating X/HTML by hand, which makes the here document in Perl
>>>> ideal for me. Also, many times a client already existing HTML code that
>>>> I can use in a script.
>>>>
>>>> -- 
>>>> Amer Neely
>>>> w:www.webmechanic.softouch.on.ca/
>>>> Perl | MySQL programming for all data entry forms.
>>>> "Others make web sites. We make web sites work!"
>>>
>>> I am not sure if this is what you are looking for, but Python has a
>>> special string with 3 quotes that I believe duplicates part of the
>>> functionality of a here document:
>>>
>>> myHmtlHeader = """
>>> <head attribute = "abc">
>>> <title>My Page</title>
>>> </head>
>>> """
>>>
>>> print myHtmlHeader
>>>
>>>
>>> outputs:
>>>
>>>
>>> <head attribute="abc">
>>> <title>My Page</title>
>>> </head>
>>>
>> 
>> Well, I have checked everything I can but I'm getting '500 Internal 
>> Server Error'. The log files aren't helpful:
>> [Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
>> of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py
>> 
>> I can't even get it to run on my home PC running Apache + Win2K. Same 
>> error.
>> 
>> My script:
>> #!/usr/bin/python
>> import cgitb; cgitb.enable(display=0, logdir=".")
>> import sys
>> sys.stderr = sys.stdout
>> print "Content-Type: text/html"
>> print
>> 
>> print """
>> <html>
>> <body>
>> <div align="center"><font style="font-family:verdana; size:18px">Hello 
>> from Python</font></div>
>> <br>
>> Goodbye.
>> </body>
>> </html>
>> """
>> 
>
>I should have added that it runs from the command line OK.
			.
			.
			.
Yes, it should work fine.  Do the things you'd do if it were Perl source:
when you say "it runs from the command line OK", do you mean invocation of
/home/softouch/public_html/cgi-bin/scratch/hello.py gives sensible results?
Does your Web server recognize that .py is a CGI extension?  What are the
permissions on /home/softouch/public_html/cgi-bin/scratch/hello.py?

Might your server have an issue with "Content-Type" vs. "Content-type"?



More information about the Python-list mailing list