views:

411

answers:

2

Hi All

I am very new to python and having to get into this stuff for a simple program to integrate with an ASP.NET application that I am building. The pseudo code is as follows.

  1. Get two parameters from request. (A ASP.NET will be calling this url by POST and sending two parameters)
  2. Internally execute some business logic and build some response.
  3. Write the response back so that the ASP.NET app can proceed.

Step 2 and 3 are already in place and working too but not able to find a solution for Step 1 (I know it should be very simple and know how to do it in Java/.NET/PHP and RoR but not in Python and the online docs/tutorials are not helping my cause). I am running python on apache using mod_python.

Any help here is greatly appreciated. Thanks in advance Vijay

+2  A: 

Here is a good beginner's tutorial for mod_python.

As far as I understand your question you have a mod_python-based script and you want to read a POST parameter. Therefore you only have to use the form object which is automatically provided by mod_python:

myparameter = form.getfirst("name_of_the_post_parameter")

You can find the documentation over here.

Note that this solution is when your server is configured with PythonHandler mod_python.psp which will allow you to use "Python Server Pages" (special <% %> tags, automatically created variables like form, ...). If you're writing a normal mod_python handler, then it would look something like that:

from mod_python import util

def handler(req):
   form = util.FieldStorage(req, keep_blank_values=1)
   myparameter = form.getfirst("name_of_the_post_parameter")
   ...other stuff...
AndiDog
Hi Thanks. This worked just right. Thx once again--V
vijay
A: 

"I know it should be very simple and know how to do it in Java/.NET/PHP and RoR but not in Python"

Well, it's not simple in Python -- the language.

It is simple in many Python web frameworks.

Don't make the mistake of comparing Python (the language) with PHP (the web framework) or RoR (the web framework).

Python, like Java or VB or Ruby, is a programming language. Not a web framework.

To get stuff from Apache into Python you have three choices.

  1. A CGI script. A dreadful choice.

  2. mod_python. Not a great choice.

  3. mod_wsgi. A much better choice.

If you're stuck with mod_python -- because this is homework, for instance -- you'll need to read a mod_python tutorial in addition to a python tutorial.

This, for example, seems to be what you're doing. http://www.modpython.org/live/current/doc-html/tut-pub.html

S.Lott
Hi.. Thanks for your clarifications. Yours and earlier posts have helped me solve this for now. I am planning to Django for all my future Python work.--V
vijay