Site5 - Built For Designers & Developers MENU

Hello World for Python

[2 Grey Star Level]

I’ve made a file in the cgi-bin directory. The contents of the file are:

#!/usr/bin/env python

print(“Content-Type: text/plain”)
print(“Hello World!”)

Then in the browser I open /cgi-bin/ 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?

Answer #1

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.

Answers Answered By: jdavey [359 Blue Star Level]

Answer #2

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!!

Answers Answered By: efreed [2 Grey Star Level]

Answer #3

You’re very welcome! Glad it worked out for you 🙂

Answers Answered By: jdavey [359 Blue Star Level]

Answer #4

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:

Line endings:

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:
From Windows:
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

From Linux:
vi 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”)
print (“”)

Python Syntax:

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

Experiment with:
import cgitb

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)

Answers Answered By: matmcnic [2 Grey Star Level]

Answer this Question

You must be Logged In to post an Answer.

Not a member yet? Sign Up Now »

Money Back Guarantees
Click to verify BBB accreditation and to see a BBB report.