error of running python code as cgi?
by shams from LinuxQuestions.org on (#5MJPJ)
This is index.html:
Code:<form action = "/cgi-bin/hello_get.py" method = "get">
First Name: <input type = "text" name = "first_name"> <br />
Last Name: <input type = "text" name = "last_name" />
<input type = "submit" value = "Submit" />
</form>and This is hello_get.py, i put in the /srv/http/cgi-bin:
Code:#!/usr/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>when i click the submit button get the error:
Code:Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: hello_get.py
If you think this is a server error, please contact the webmaster.
Error 500
my.example.net
Apache/2.4.48 (Unix) mod_fcgid/2.3.9 mod_wsgi/4.8.0 Python/3.9i can run the .pl and .sh codes from the /srv/http/cgi-bin but get the above error with all .py codes when running from the cgi-bin directory.
Code:<form action = "/cgi-bin/hello_get.py" method = "get">
First Name: <input type = "text" name = "first_name"> <br />
Last Name: <input type = "text" name = "last_name" />
<input type = "submit" value = "Submit" />
</form>and This is hello_get.py, i put in the /srv/http/cgi-bin:
Code:#!/usr/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>when i click the submit button get the error:
Code:Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: hello_get.py
If you think this is a server error, please contact the webmaster.
Error 500
my.example.net
Apache/2.4.48 (Unix) mod_fcgid/2.3.9 mod_wsgi/4.8.0 Python/3.9i can run the .pl and .sh codes from the /srv/http/cgi-bin but get the above error with all .py codes when running from the cgi-bin directory.