I’ve made a hello.py file in the cgi-bin directory. The contents of the file are:
Then in the browser I open /cgi-bin/hello.py and get a 500 server error.
I’ve tried with/without parenthesis on the print lines.
I’ve tried using the web file manager to set file permissions to 777.
Where do I get more information about this error?
Should this work, or what should I be doing?
Hello! Try setting the first line to the following:
Then set the permissions to 755 rather than 777, and it should work normally for you.
All I needed was the permissions at 755, with that even the generic #!/usr/bin/env python worked. I had no idea I could break it by granting too many permissions.
Thank you much!!
You’re very welcome! Glad it worked out for you 🙂
Here are a few notes on things that can cause Server Error 500:
If you use chmod 777, 757 or 775 it causes the error.
See these links:
Lines in your python file must use Unix line endings \n (0x0a).
Windows saves text files with a \r\n (0x0d 0x0a).
If you save in MS-Dos format from a windows editor you will have the wrong line endings.
To see if a file has the wrong line endings you can pipe it through xxd:
You can fix the line endings by one of the methods below:
Wordpad: Save in non-MS-Dos format. Save As… | Save as type: Text Document (instead of Text Document – MS-DOS Format)
Notepad++: open the file then Edit | EOL Conversion | Unix/OSX Format
vi test.py then (esc) :set fileformat=unix
The Content Line:
You need a line feed after the content line:
print (“Content-type: text/html\n”)
print (“Content-type: text/html”)
If you change your python interpreter to /usr/local/bin/python3.0 then scripts written in 2.x may fail (for example 3.x requires that print statements be in parentheses, etc.)
Be sure to check your error log to see what is causing the 500
Check your script for syntax errors by running it in the shell: python test.py
Notice we specified the shell like this:
You can look and see what you have available like this:
Login to Site5 backstage
Site Admin to your site
Programming Center | Python
(You can also ls /usr/bin and /usr/local/bin to see what pythons are installed)
You must be Logged In to post an Answer.
Not a member yet? Sign Up Now »