2

I put a simple python script inside the cgi-bin in apache2 and tried to execute it using the browser as follows,

"http://www.example.com/cgi-bin/test.py"

But it gives a 500 Internal sever error.

Following is the error.log in apache2.

[Sun Jul 29 22:07:51 2012] [error] (8)Exec format error: exec of '/usr/lib/cgi-bin/test.py' failed [Sun Jul 29 22:07:51 2012] [error] [client ::1] Premature end of script headers: test.py [Sun Jul 29 22:07:51 2012] [error] [client ::1] File does not exist: /var/www/favicon.ico

can anyone help me on this?

2
  • 1
    Well, if you gave your source code... >_> Commented Jul 29, 2012 at 18:08
  • Please stop shooting yourself in the foot, nobody does python for the web as CGI nowadays, you'll even be seen as the "weird" guy if you try to use mod_python for Apache. Please use a WSGI framework, there's many of them to choose from. Bottle, Flask or web.py can be a good start. Commented Jul 29, 2012 at 18:39

2 Answers 2

1

Looks like you're not sending the headers properly.

Try if this simplest example script runs:

print('Content-Type: text/html; charset=utf-8\n')
print("Hello, World!")
Sign up to request clarification or add additional context in comments.

1 Comment

No I sending that correctly as you said. But issue is same . . . .
1

BlaXpirit's answer should solve your problem with a 500 server internal error.

It is important to note the "\n" at the end of the first print statement. You can also write it as

print("Content-Type: text/html; charset=utf-8")

print()

I was surprised to learn that writing out these headers is necessary even if your Python program is only going to do server-side work - with no response to the browser at all.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.