internal server error (500) in simple cgi script

青春壹個敷衍的年華 提交于 2019-12-05 03:30:57

You might need a #!/usr/bin/python at the top of your script to tell Apache to use Python to execute it. At least, I did that and it worked for me :-) .

Also, save the file (if this is a Linux server) with Unix line endings. You did make it executable using chmod +x didn't you?

You can use #!/usr/bin/env python to cover the current running Python version if you're running in various environments (hence the env part).

It looks like Apache has trouble executing it. Typically for a unix script you also need to specify the interpreter at the top of the script.

Try adding this to the top:

#!/usr/bin/python

Putting

#!/usr/bin/env python

on the top of the script works fine. I put it on top, but Netbeans was putting extra code (import commands) by itself on the top of the page which drove me crazy :(

Heitor Giacomini

Maybe your problem is that new python version needs parentheses ( ).

So your:

print "<body>"

Now should to be:

print ("<body>")

remove the 2nd line in your program (print) I tried it on my apache server (mac os x) it works fine. don't forget to chmod 755 and reboot with sudo apachectl restart This is for python 2.7

print "Content-type: text/html"
print "<html><head><title>CGI</title></head>"
print "<body>"
print "hello cgi"
print "</body>"
print "</html>"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!