1

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.

Thanks for suggestions and help.

<form action="/cgi-bin/hello_world.py" method="post">
   IP Address: <input type="text" name="user_name"><br />
   Password: <input type="text" name="pass_word" />
   <input type="submit" value="Submit" />
</form>

My python script is

#!/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 "<html>"
print "<head>"
print "<title>Hello </title>"
print "</head>"
print "<body>"
print "<h2> %s is IP  and  %s is passowrd</h2>" % (user_name, pass_word)
print tc.read_all()
print "</body>"
print "</html>"
NoviceInPython
  • 113
  • 1
  • 2
  • 9
  • 1
    Internal server error 500 implies that executing the script failed. I can't see anything inherently wrong with your script. Have you looked at the web servers log files? – Emilia Bopp Mar 25 '14 at 17:50
  • Yes, I looked into www/error/ there are .var log files. There it does not mention any error. Am I looking in correct error log location? – NoviceInPython Mar 25 '14 at 18:01
  • As @aeosil0n said, please post the relevant snippets from your apache (or whatever server you are using) error log. Maybe the user with which this script is run via CGI mustn't use telnet. – Hyperboreus Mar 25 '14 at 18:01
  • This script if I run separately runs well and gives correct output. But If I run it from html file using form action, this gives internal 500 error – NoviceInPython Mar 25 '14 at 18:03
  • All I have to do is take command output from the python script and when they enter username password and submit in the html file, I need to put that command output in web page – NoviceInPython Mar 25 '14 at 18:04
  • How would I print what exception is caused ? – NoviceInPython Mar 25 '14 at 19:01

0 Answers0