Jump to content

Recommended Posts

Posted

Well, I was told to come here in a help desk ticket, but I still am not sure what to do. I wrote this test file and put it in my cgi-bin:

 

>#!/usr/bin/python
# Filename: test.py

length = 5
breadth = 2

area = length * breadth
print 'Content-Type: text/html'
print 'Area is', area
print 'Perimeter is', 2 * (length + breadth)

 

Whenever I try to run the file, I get a 500 Internal Server Error. I was told to try the path /user/bin/python2.2, but that didn't work either.If anybody has a solution, it would be much appreciated.

Posted

This isn't really a python problem. In any script that is outputting to a web browser, there has to be a blank line separating any HTTP header lines from the actual page content (that's how the web server knows where the HTTP header ends and the page content starts).

 

Your script works correctly (no 500 error) if you add an extra 'print' command as I have it below:

>#!/usr/bin/python
# Filename: test.py

length = 5
breadth = 2

area = length * breadth
print 'Content-Type: text/html'
print
print 'Area is', area
print 'Perimeter is', 2 * (length + breadth)

  • Like 1
  • 7 months later...
Posted (edited)

We mainly use php but we want to get familiar with python in case we use it for the google sitemap.

 

We've used one perl cgi script and that was simple, we just put the file in our x.com/cgi-bin directory and everything was cool.

 

If we want to use the test.py sample file in this thread then where do we put it in our file system (and please don't say /usr/bin/python, rather tell me where to look in ftp) ? In other words, one can find the perl directory by going to www then searching for the cgi-bin subdirectory, how do we do the same thing for python?

 

Thanks,

Eric

Edited by esprague
Posted

CGI scripts (perl or python) can be placed in your /public_html directory (same as /www) or any subdirectory below it. If you like the extra security offered by the /public_html/cgi-bin directory, you can place them there, but you don't have to.

 

If you decide to place the file somewhere within /public_html but outside of the /public_html/cgi-bin directory, you should rename the file to test.cgi so the web server will recognize it as a file to be executed instead of displayed.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...