简体   繁体   中英

Python CGI Script Not Executing

Just doing a basic python project with HTML file, i came across a tutorial which gave an idea about how i can execute the code,

here is the HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Admin Login</title>
</head>
<body>
<big><big>Login
Here<br>
<br>
</big></big>
<form action="/var/www/cgi-bin/Login.py" name="LoginForm"><big>Administration
Login<br>
 User Name<br>
  <input name="UserName"><br>
  <br>
  <br>
Password<br>
  <input name="PassWord"><br>
  </big><br>
   <br>
  <br>
<input type="submit">
  <br>
</form>
&nbsp;__&nbsp;<br>
</body>
</html>

and the python code..

#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
# get the info from the html form
form = cgi.FieldStorage()
#set up the html stuff
reshtml = """Content-Type: text/html\n
<html>
 <head><title>Security Precaution</title></head>
 <body>
 """

print reshtml 

User = form['UserName'].value
Pass = form['PassWord'].value

if User == 'Myusername' and Pass == 'MyPasword':
    print '<big><big>Welcome'
    print 'Hello</big></big><br>'
    print '<br>'
else:
    print 'Sorry, incorrect user name or password' 

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

The problem is, when i submit the username and password, it just shows the whole code back on the browser and not the required Welcome message :(. I use Fedora13 .. can anyone tell me what is going wrong? I even changed the permissions of the file(s).

Most likely, your webserver is not configured to execute the script. Even if it's marked as 'executable' in the file system, that doesn't necessarily mean the webserver knows that it should be executing .py files (rather than just serving them 'straight up'). Have a look here if you're running Apache: http://httpd.apache.org/docs/2.0/howto/cgi.html

<form action="/var/www/cgi-bin/Login.py" name="LoginForm">

Try

<form action="/cgi-bin/Login.py" name="LoginForm">

/var/www is probably the path from your ftp site. The web server will only look inside /var/www, so it puts that part there automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM