rnpg1014 Posted August 13, 2005 Posted August 13, 2005 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. Quote
TCH-Bruce Posted August 13, 2005 Posted August 13, 2005 Did you upload the file in ASCII mode? Not Binary and change the permissions to 755. Quote
rnpg1014 Posted August 13, 2005 Author Posted August 13, 2005 I didn't upload the file really, I made it there via Cpanel, is that my problem? Quote
TCH-Bruce Posted August 13, 2005 Posted August 13, 2005 Did you change the permissions to 755 so that you could execute it? If not the permissions are likely 644 which will not execute and thus produce an error. Quote
rnpg1014 Posted August 13, 2005 Author Posted August 13, 2005 Yes, the permissions are set to 0755, as well as the permissions of the cgi-bin. Quote
TCH-Bruce Posted August 13, 2005 Posted August 13, 2005 Sorry, I have no experience with Python. Maybe one of our other users that has used it will be able to offer assistance. Quote
TweezerMan Posted August 13, 2005 Posted August 13, 2005 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) 1 Quote
rnpg1014 Posted August 13, 2005 Author Posted August 13, 2005 Well that's very interesting, thanks a lot for the help. Quote
esprague Posted April 4, 2006 Posted April 4, 2006 (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 April 4, 2006 by esprague Quote
TweezerMan Posted April 4, 2006 Posted April 4, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.