我有这个hello_world.py脚本,它接受用户名和密码并打印用户信息。另外python执行没有任何错误。但是,当我从HTML提交时,html页面会给出内部服务器500错误。我在httpd.conf中为文件系统中的脚本添加了可执行权限。但是,当我提交提交时,我不确定为什么这不会执行。
感谢您的建议和帮助。
<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>
我的python脚本是
#!/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>"