Making Python scripts work on MAMP

7.3k views Asked by At

I'm using mamp server for testing out all my web pages. I'm new to python. I'm able to run a script in python interpreter that will normally print a hello world.

print "Hello World!"   

So i used the same line in a file with name test.py . So how should I run this on web.

As am new to python, i tried some normal things, placing test.py in /htdocs/cgi-bin/ and trying to open it. But it says forbidden page.

Anyone please help me making this work. Thanks

2

There are 2 answers

6
GreenMatt On

To do this with CGI, I recommend reading the Python CGI docs. At a minimum, you need to output the content type and html tags:

print "Content-Type: text/html"
print
print "<html>"
print "<head>"
print "<title>Example of Python CGI script</title>"
print "</head>"
print "<body>"
print "Hello World!"
print "</body>"
print "</html>"

Also, make sure the web server software has permission to execute the script. You should be able to use chown to set the ownership and chmod to set the permissions.

0
AudioBubble On

Know this is an old post but I'll add my two cents.

I place my *.py scripts in /Applications/MAMP/cgi-bin

start my scripts with #!/bin/usr/python

                  print "Content-type:text/html \r\n\r\b"

then chmod 755 .py and run it with ./.py from cgi-bin directory

Hope this helps :)