Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

how to run a python file on Safari?

Good day,

I am trying to run any python file on the Leopard web server, accesing it via safari.
also I have set the permissions of the file to 777...
then I have copied the file to library/webserver/documents.When I open this file in Safari, the file is listed, but it is not executed.

also I have copied the file to library/webserver/cgi-executables, but the file is not executed, an error appears:
Internal Server Error

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

Please contact the server administrator, you@example.com 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
----
the python file contains only 2 lines:

#!/usr/bin/env python
print 2
-------
I have tested the file in the command line via python test.py and it runs fine... but I dont know what should I have to do to run it on the browser...

do I have to enable mime types for python on leopard client? how to do it?


have a nice day

Quad MaC Pro & Dual 2 GHz PowerPC G5, Mac OS X (10.5.2), 16gb ram,leopard client

Posted on Apr 29, 2008 5:49 PM

Reply
5 replies

Apr 29, 2008 10:05 PM in response to avalokitesvara

Check the httpd error logs. On OS X client, that's /var/log/httpd/error_log; it's also worth checking /var/log/httpd/access_log.

Since it's the server that's supposed to be executing it, you shouldn't have to enable mime types on the Leopard client. Any problems are solely on the httpd side.

Note that the script you've given doesn't produce a valid HTML page. How your browser chooses to render '2' is undefined. However, I don't think this is the problem you're seeing right now...

May 7, 2008 6:15 AM in response to Karl Zimmerman

Karl Zimmerman wrote:
Note that the script you've given doesn't produce a valid HTML page. How your browser chooses to render '2' is undefined. However, I don't think this is the problem you're seeing right now...


Actually, you're right, that is the problem: there's no HTTP header. The script needs this line:

print 'Content-type: text/html '


before anything else is sent to the browser, and it will work. At least, it works with Apache 1.3 in Tiger, but I'd expect it to be the same with Apache 2.

charlie

May 9, 2008 8:27 AM in response to Karl Zimmerman

Karl Zimmerman wrote:
Wow! So the server itself does some syntax checking on the document generated by a CGI script, and refuses to serve it if it doesn't provide at least enough information to allow HTTP headers to be generated? Cool!


Right, otherwise, the client wouldn't know how to display the data it receives. So the first thing you "print" back has to be something to tell the client how to handle the response: whether it's text/html, text/plain, image/jpeg, or some kind of redirect...

charlie

how to run a python file on Safari?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.