Error500 with a python script!

software development

#1

Hi,

i was trying to use a python script but it always returns an 500 internal server error.

The script is very simple. I have tried to use the example of the the dreamhost wiki but it doesnt work either.

“”"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#!/usr/bin/python

def main():
print "Content-type: text/html"
print
print ""
print "Hello World from Python"
print ""
print "Standard Hello World from a Python CGI Script"
print “”

if name == “main”:
main()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@uguu-web.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

Heeeeelp! >_<


#2

Do you have the access to error.log file? Please check the log and see what it says.

Most of the time, Internal Server Error is caused by syntax error. Please have [color=#CC0000];[/color] at the end of each line of your code. And you may want to try

print “Content-type: text/html[color=#CC0000]\n\n[/color]”

You have to have two empty lines after the header.

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#3

Programming partner here. Error log says:


[Wed May 07 00:20:34 2008] [error] [client 84.127.104.121] Premature end of script headers: webtest.py

…and then some 404s about the personalized 500 error page. I added the \n’s and the result is the same. I also simplified the code to this:


#!/usr/bin/python
print "Content-type: text/html\n\n"
print “Hello World from PythonStandard Hello World from a Python CGI Script”

It’s not a syntax problem, methinks. And the script works locally. You can see for yourself, the script is located on http://www.uguu-web.com/webtest.py


#4

What is the file permission on the py file? You’ll need execute permission on the file.

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#5

It’s 755. I tried with 777 too.

…but, somehow, it started working just now. Odd.


#6

Strange… Now let’s shake legs :slight_smile:

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#7

Try this one: [code]#!/usr/bin/python

for linux

import sys
import os

def printHeader():
print “Content-type: text/html\n”

def printArgs():
for arg in sys.argv:
print arg + "
"
def printEnv():
for key in os.environ.keys():
print “” + key + “=” + os.environ[key] + “

def printVersion():
print “Python %s” % sys.version

def main():
printHeader()

print "Hello World from Python"
print “Standard Hello World from a Python CGI Script”

print "

Python Info…
"
print ""
printVersion()
print “

print "

Command Line…
"
print ""
printArgs()
print “

print "

Environment…
"
print ""
printEnv()
print “

if( name == “main”):
main()
[/code]Note that you need to use a *nix editor, or in some other way make sure you have proper *nix style line endings. Failure to do so will often result in the kinds of errors you are seeing. :wink:

–rlparker


#8

The 500itis is back again. Unix style lines and everything. I named the script from rlparker “tests.py”. It returns a 500, and error.log says:


[Fri May 09 11:12:38 2008] [error] [client 130.206.30.217] Premature end of script headers: tests.py
[Fri May 09 11:12:38 2008] [error] [client 130.206.30.217] File does not exist: /home/uguues/uguu-web.com/internal_error.html

My own webtest.py:


#!/usr/bin/python
print "Content-type: text/html\n\n"
print “Hello World from PythonStandard Hello World from a Python CGI Script”

…does the same. Everything is 777 and unix style. You can check on http://www.uguu-web.com/uguuplanet/


#9

Or your webtest.py (chmod 755)

rewritten as

[code]#!/usr/bin/python
print “Content-type: text/html\n\n"
print “””

Hello World from PythonStandard Hello World from a Python CGI Script """ [/code]should work.


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK! :@

Act on my advice at your own risk!


#10

I think you meant triple single quotes, not double. I tried with both options just in case, and it does the same thing. I don’t think it’s a problem of the script itself, it works with my local apache >_<


#11

No I used triple double quotes and in the editor added a blank line at the end of the script.


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK! :@

Act on my advice at your own risk!


#12

Well, that doesn’t work either.


#13

777 will not work under suExec on DreamHost,iles to be executed as CGI need to be 755 or more restrictive. Period. Pythin is picky about editors, blank lines, extra characters. Etcetera.

The code I posted works fine, on a DH server, when properly prepared, upload, chmodded, etc.

http://maddogz.com/dev/python/pytest.py
http://maddogz.com/dev/python/pytest2.py

The same code for both above links, prepared with different *nix editors in the shell. :wink:

–rlparker