0

I need help with how to run scripts test.cgi for example in apache ? I created test script:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!

When I runlocalhost/cgi-bin/test.cgi

It gives me error.

Internal Server Error

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

Please contact the server administrator, webmaster@localhost 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.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Python is installed properly. Test.cgi chmod is 755

I am new to linux. On wndows it gives me error too . On windows it gives me:

End of script output before headers: python_test.cgi

I use this script on windows:

#!"C:\Python34\python.exe"
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"

Any idea ?

2
  • can you please show the configuration in your httpd.conf file ? Commented Dec 19, 2014 at 10:56
  • In linux is empty and windows is ok cause perl scripts works fine. I added LoadModule cgi_module modules/mod_cgi.so and AddHandler cgi-script .cgi .pl .asp .py Commented Dec 19, 2014 at 11:37

1 Answer 1

2

Add these to your configuration file:

  <Directory "/opt/lampp/htdocs/xampp/python">
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
      Order allow,deny
      Allow from all
  </Directory>

and replace your code with:

import cgitb
cgitb.enable()

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

print ("Hello World!")

It worked for me. In Python 3.x print is a function, so you have to pass the string to be printed as an arguement.

Sign up to request clarification or add additional context in comments.

3 Comments

On windows ? I use xampp on windows and only apache on linux.
Yes, there would be a httpd.conf file in xampp
I know, I edited it before to enable cgi_mod. I andded it but it did not work. I am using python3.4 can it make this error ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.