title: Display python script output to HTML page
body: <p>I have this hello_world.py script which takes username and password and prints user information. Separately the python executes without any error. But, when I submit from HTML the html page gives internal server 500 error. I have added executable permission to script in file system, in httpd.conf. But, I am not sure why this is not executing when I provide submit.</p>
  
  <p>Thanks for suggestions and help.</p>
  
  <pre><code>&lt;form action="/cgi-bin/hello_world.py" method="post"&gt;
     IP Address: &lt;input type="text" name="user_name"&gt;&lt;br /&gt;
     Password: &lt;input type="text" name="pass_word" /&gt;
     &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My python script is</p>
  
  <pre><code>#!/usr/bin/python
  
  # Import modules for CGI handling 
  import cgi, cgitb
  import getpass
  import sys
  import telnetlib
  
  
  # Create instance of FieldStorage 
  form = cgi.FieldStorage()
  
  # Get data from fields
  user_name = form.getvalue('user_name')
  //username will get IP of machine
  pass_word  = form.getvalue('pass_word')
  
  loginid = 'admin'
  
  tc = telnetlib.Telnet(user_name)
  tc.read_until("login: ")
  tc.write(loginid + "\n")
  tc.read_until("Password: ")
  tc.write(pass_word + "\r\n")
  
  tc.write("ls -l\n")
  tc.write("exit\n")
  
  
  print "Content-type:text/html\r\n\r\n"
  print "&lt;html&gt;"
  print "&lt;head&gt;"
  print "&lt;title&gt;Hello &lt;/title&gt;"
  print "&lt;/head&gt;"
  print "&lt;body&gt;"
  print "&lt;h2&gt; %s is IP  and  %s is passowrd&lt;/h2&gt;" % (user_name, pass_word)
  print tc.read_all()
  print "&lt;/body&gt;"
  print "&lt;/html&gt;"
  </code></pre>