By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,510 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

Quickest way to make py script Web accessible

P: n/a
What is the quickiest and easiest way to make a py script run on a Web
server? I have access to an Apache Web server running on Linux.

I'm often asked to run some of my scripts on behalf of others. My hope
is to make a simple Web-based interface where people could run the
scripts themselves whenever they like... instead of asking me.

I'd rather not rewrite the scripts with PHP. Any tips on a fast, easy
way of doing this?

Thanks!

Jan 5 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a

rt*****@vt.edu wrote:
What is the quickiest and easiest way to make a py script run on a Web
server? I have access to an Apache Web server running on Linux.

I'm often asked to run some of my scripts on behalf of others. My hope
is to make a simple Web-based interface where people could run the
scripts themselves whenever they like... instead of asking me.

I'd rather not rewrite the scripts with PHP. Any tips on a fast, easy
way of doing this?

Thanks!


I haven't tried it myself, but have you looked into
http://www.modpython.org/?

--
-Todd
http://www.signalsguru.net

Jan 5 '06 #2

P: n/a
Jim
rt*****@vt.edu wrote:
What is the quickiest and easiest way to make a py script run on a Web
server? I have access to an Apache Web server running on Linux.

I'm often asked to run some of my scripts on behalf of others. My hope
is to make a simple Web-based interface where people could run the
scripts themselves whenever they like... instead of asking me.

Perhaps I'm not understanding the question, but ..

Can you write a CGI script that calls the desired program using
Python's system call, like:
os.system("/home/rtilley/cleanup.py")
and then returns a little HTML saying that the cleanup was done at
such-and-such a time?

Is that what you are asking to do?
Jim

Jan 5 '06 #3

P: n/a
Karrigell lets you run pure python scripts, although not directly in
Apache.
It uses its own server running behind apache.

You can code in 4 styles:

-pure python scripts
-python in html (like in PHP)
-html in python
-karrigell services (mapping functions to urls)

http://karrigell.sf.net

Hope this helps...
Luis

Jan 5 '06 #4

P: n/a

rt*****@vt.edu wrote:
What is the quickiest and easiest way to make a py script run on a Web
server? I have access to an Apache Web server running on Linux.

I'm often asked to run some of my scripts on behalf of others. My hope
is to make a simple Web-based interface where people could run the
scripts themselves whenever they like... instead of asking me.

I'd rather not rewrite the scripts with PHP. Any tips on a fast, easy
way of doing this?

Thanks!


If it's just using the web to *run* a python script on the server, then
a simple cgi-script which will spawn a process for other scripts.

You need a web form that permit the user to choose the script he/she
wants executed.

That form will point (action='your_cgi_script.py') to the script who's
job will be to spawn the other script, submitting the user choice.

One HTML page for the script choices and one extra python script to
receive the cgi call, seems easy!

If it doesn't look that way to you, don't hesitate to let it be known,
and on which part...

Jean-Marc

Jan 5 '06 #5

P: n/a
I apologize for my inital ambiguity.

Say I have a .py script that gets email addresses from a database and
then sends messages to customers (this is not spam, these guys _want_
to get the emails). Historically, IT has executed the script when
someone in Marketing makes a request. I want to make it so that
Marketing can run the script themselves by executing the script through
a Web-based interface. I don't want to have to alter the script a great
deal in order to do this.

Jan 5 '06 #6

P: n/a
This works well! Thanks for the advice. The docs for it should include
something about adding content_type = 'text\plain' otherwise, the
'testing' section of the tutorial is broken

It should look like this:
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

Not this:
from mod_python import apache
def handler(req):
req.write("Hello World!")
return apache.OK

Jan 5 '06 #7

P: n/a
Thank you all for the advice and suggestions. I appreciate the time you
took to help!

Jan 5 '06 #8

P: n/a

rt*****@vt.edu wrote:
I apologize for my inital ambiguity.

Say I have a .py script that gets email addresses from a database and
then sends messages to customers (this is not spam, these guys _want_
to get the emails). Historically, IT has executed the script when
someone in Marketing makes a request. I want to make it so that
Marketing can run the script themselves by executing the script through
a Web-based interface. I don't want to have to alter the script a great
deal in order to do this.


I think my previous suggestion was just on the nose - none of your
scripts need be modified EXCEPT if they entail user input, for which
you would have to a web form to get such info from your user. and have
your cgi call your mail program with the parameters submitted from the
web form (such group of customers, such message, etc).

An alternative to spawning a process, is importing the mail script
within the cgi script itself (conditionnaly if need be).

Jan 5 '06 #9

P: n/a
Turning a script into a CGI is a brain-dead easy way of web-enabling a
script.

You could even make the script dual purpose by checking for the
existence of CGI environment variables. If they exist the script is
running as a CGI.

There are lots of resources on the internet on how to write CGIs.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

Jan 7 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.