convergedtarkus
convergedtarkus

Reputation: 697

Internal server error with simple .cgi, what is wrong?

I'm in internet programming, and we are doing .cgi, but for the life of me, I cannot get my .cgi script to run at all, I know other people have it working, but mine just refuses to run. Any suggestions?

#!/usr/bin/env python

print "Content-type: text/html"
print
print "<html><head><title>CGI</title></head>"
print "<body>"
print "hello cgi"
print "</body>"
print "</html>"

I have chmod 755 the file multiple times, i have tried using #!/usr/bin/python and #!usr/local/bin/python. I tried putting it in a folder named cgi-bin and I've made sure that it is saved with unix line endings, but all I ever get is internal server error. I know I had it working in class, but now it just refuses to run, any help guys? Thanks?

Upvotes: 2

Views: 1187

Answers (2)

convergedtarkus
convergedtarkus

Reputation: 697

Ok, this is a really easy fix that I totally missed. First off Ned Batchelder correctly pointed out that my code is python 2 (which is weird since I use python 3) but the problem is the print statement after the, print("Content-type: text/html"). The second print statement has to be print("") not just print(). So i feel a little stupid, but that fixed the issue for me, hope this helps someone else!

Upvotes: 1

Ned Batchelder
Ned Batchelder

Reputation: 376022

Wild guess: you are using Python 3, so your print statements have to be print function calls:

print("Content-type: text/html")
etc...

Upvotes: 1

Related Questions