[Tutor] cgi not executed when accessed through browser

runsun runsun@bilbo.bio.purdue.edu
Sat, 20 Jul 2002 18:34:39 -0500


Thx for the replies but it still unsolved.

First of all, you don't need the <html> and <body> tags for a 
browser to read a document as html one. For example, a simple 
file containing only one line:

<font color=red> This is red </font>

will show up red on a browser, without <html> and <body> tags.

Therefore, the fact that my original code didn't contain these
tags can't be the reason for not showing correctly in a browser.

I did add: 

	print '<html>' 
            print '<body>'

but it didn't help.

The problem is that the cgi file was NOT EXECUTED when 
accessed through a browser, but only READ instead. It's 
executed when accessed from a command line on the server.



] Message: 8
] Date: Sat, 20 Jul 2002 01:01:49 -0400
] From: Kirk Bailey <idiot1@netzero.net>
] Organization: Silas Dent Memorial Cabal of ERIS Esoteric and hot 
] dog boiling society
] To: "tutor@python.org" <tutor@python.org>
] Subject: Re: [Tutor] cgi not executed when accessed through browser
] 
] Yep. It's not a html page.
] 
] Read below.
] 
] runsun wrote:
] > 
] > Hi all,
] > 
] > I have a simple python-based cgi :
] > 
] > ===================[ content of test.cgi ]===========
] > #!/opt/bin/python
] > import os
] > 
] > print "Content-type: text/html\n\n"
] >
] See, from now on, the server treats it as a html page- and so does the
] browser.
] No body tag, no <HTML> tag. What's a browser to do?
]  
] > print "hello\n"
] '\n' is useless in html. CARRIGERUTURNS are IGNORED.
] 
] > print os.listdir("..")
] >
] All one line in  html I fear. UNLESS one preceeds it with the <PRE> tag. 
] > print "\n"
] Likewise ignored.
] 
] > 
] > print os.listdir("../..")
] > ============================================
] > 
] > It was executed as expected when called from command line
] > in my unix account.
] sure it was, the telnet client is not a html browser.
] > But when it was called through a browser,
] > it didn't print out the listdir that I expected, but displayed the
] > entire code content as text on my browser.
] >
] And probably included formatting discrepancies you did not mention.
] {Possibly you did not notice? Not meaning to hurt feelings.)
]  
] > Any help ?
] > 
] Was my reply any help? Want a sample hello world script?
] 
] > pan
] > 
] > ============================================
] >   ~~ Be like water, be shapeless ~~
] >    Runsun Pan, PhD, 773-834-3965
] >  Ecology & Evolution, U of Chicago
] > ============================================
] > 
] > 
] > _______________________________________________
] > Tutor maillist  -  Tutor@python.org
] > http://mail.python.org/mailman/listinfo/tutor
] 
] -- 
] 
] end
] 
] Respectfully,
]              Kirk D Bailey
] 
] 
] +---------------------"Thou Art Free." -Eris-----------------------+
] | http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
] | http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
] +------------------Thinking| NORMAL |Thinking----------------------+
]                            +--------+
] -------------------------------------------
] Introducing NetZero Long Distance
] Unlimited Long Distance only $29.95/ month!
] Sign Up Today! www.netzerolongdistance.com
] 
] 
] 
] Message: 10
] Date: Sat, 20 Jul 2002 01:21:35 -0400
] From: Kirk Bailey <idiot1@netzero.net>
] Organization: Silas Dent Memorial Cabal of ERIS Esoteric and hot 
] dog boiling society
] To: "tutor@python.org" <tutor@python.org>
] Subject: Re: [Tutor] cgi not executed when accessed through browser
] 
] My first simple one.
] 
] ns# list first.py
] Listing of file first.py in directory:/www/www.howlermonkey.net/cgi-bin
] 
] #!/usr/local/bin/python
] print "Content-type: text/html"
] print
] print "<title>First program</title></head>"
] print "<body bgcolor=\"FFFFFF\" text=\"000000\" link=\"0000FF\">"
] print '<P>'
] print "Hello world!"
] print '<P>'
] print '</body></html>'
] 
] And then a not so simple one:
] 
] ns# list helloworld.py
] Listing of file helloworld.py in
] directory:/www/www.howlermonkey.net/cgi-bin
] 
] #!/usr/local/bin/python
] #import cgi
] print "Content-Type: text/html"     # HTML is following
] print                               # blank line, end of headers
] print "<TITLE>CGI script output</TITLE>"
] print "</head>"
] print "<body bgcolor=\"#FFFFFF\" text=\"#000000\" ><blockquote>"
] print "<P>"
] print "<center><H1>This is my first CGI script</H1></center>"
] print "<P>\n<br>"
] print "Hello, world!"
] print "<P>"
] print "this is my very first python cgi script, and it works! YAHOO!"
] print "<p>"
] print "getting the quotes in the BODY statement to come out failed until
] I remem
] bered"
] print "to ise a \\ in front of the quote so it would be a literal
] instead of a "
] print "end to a print declaration. So exxcited I plum forgot, ant
] really,"
] print "that's the same as in a shell script, pure human stupidity and
] ham handed
] ness,"
] print "but it's fine <i>NOW</i>. Ya know, I could do a file copy in and
] print ou
] t and"
] print "store the content as a simple heml file, and less work on
] changing or cre
] ating"
] print "the scripts... hmmm..."
] print "<P>\n<br>"
] print "</html>"
] print "</body>"
] 
] 
] ns#
] 'list' is a shell script I wrote, which is so simple it is disgusting.
] 
] ns# list /usr/local/sbin/list
] Listing of file /usr/local/sbin/list in
] directory:/www/www.howlermonkey.net/cgi-bin
] 
] #! /bin/sh
] echo -n Listing of file $1 in directory:
] pwd
] echo
] more < $1;
] echo
] 
] Home some of this helps.
] 
] -- 
] 
] end
] 
] Respectfully,
]              Kirk D Bailey
] 
] 
] +---------------------"Thou Art Free." -Eris-----------------------+
] | http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
] | http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
] +------------------Thinking| NORMAL |Thinking----------------------+
]                            +--------+
] -------------------------------------------
] Introducing NetZero Long Distance
] Unlimited Long Distance only $29.95/ month!
] Sign Up Today! www.netzerolongdistance.com
] 
] 
] 
] 
] --__--__--
] 
] _______________________________________________
] Tutor maillist  -  Tutor@python.org
] http://mail.python.org/mailman/listinfo/tutor
] 
] 
] End of Tutor Digest
]