Jump to content

Recommended Posts

Posted

Hi all,

 

I am trying to write my first CGI script using Python on my shared virtual web server. I put the script under 'public_html' in the 'cgi-bin' folder on my web server. I made the script executable with the chmod +x command. For the she-bang I am using #! /usr/bin/env python so that the script will be able to find any Python interpreter and not a specific one at a specific location.

 

I made a test form to call the script from when a button is clicked but I just receive a 500 Internal Server error when trying to run this script. I messed around some with the location of the cgi script, which is a .py file in this case, but only received 404 errors.

 

Does anyone reading this know what I am missing?

 

Here is my Python script:

 

#! /usr/bin/env python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my third or fourth or so CGI program</h2>'
print '</body>'
print '</html>'

 

 

Here is my HTML code that calls the Python script:

 

<!DOCTYPE html>
<head>
<title>Test CGI Scripting With Python</title>
</head>
<body>
<center>
<form action="cgi-bin/hello.py" method="post">
Click this button
<input type="submit" value="Submit" />
</form>
</center>

</body>
</html>

 

 

Thank-you for reading this everybody. :D

 

Respectfully,

 

minus

  • 3 weeks later...
Posted

Cool. :D Thank-you for the help. I will try this shebang.

 

Actually, I just changed the she-bang and still receive a 500 Internal Error. :/ :(

  • 1 month later...
Posted

I figured out my coding problem. I had to set the permissions to 0755! This was in addition to the other change of specifying the exact path to the python interpreter. :P

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...