[Tutor] CGI-version not working while similar command-line script is fine

Gerhard Venter s.venter at ntlworld.com
Fri Sep 3 17:53:16 CEST 2004


Hi all

I'm trying to convert the following little code (which works fine if you 
have lynx installed) into CGI:

#! /usr/bin/env python
import os
websitename = raw_input('enter a website: ')
command = 'lynx --dump ' + websitename
k=os.popen(command, 'r')

for line in k.readlines():
       print(line)
------------------------------------------------
My CGI version  produces no errors, only a blank page.   I have other 
Python CGI scripts, so it is not about web server config.  I have also 
tested my HTML form, and was able to print the value of websitename to 
HTML, so I know the form passes the data to the script.

import cgi, os
import cgitb; cgitb.enable()
<>form = cgi.FieldStorage()
website = form["websitename"].value
command = 'lynx --dump ' + websitename
k=os.popen(command, 'r') 

<>print 'Content-type: text/plain'
print
 
for line in k.readlines():
       print(line)
-------------------------
I suspect there is a hint in the fact that I had to use raw_input 
instead of just input for the cmd-line version (just input causes a 
NameError).   Maybe the CGI-module has its own version of this effect
Any pointers  welcome.

Gerhard



More information about the Tutor mailing list