Re: server side parameters

Graham Dumpleton <[email protected]> Thu, 7 Jan 2010 20:56:28 +1100
Newsgroups gmane.comp.python.mod_python
Message-ID <[email protected]>
If you are getting a 403 forbidden error then you either haven't
configured Apache correctly such that the mod_python URL you are using
is a valid URL which can be accessed, that the specific URL is
matching some pattern elsewhere in Apache which is denied for some
reason, or, you have named your publisher handler with a leading
underscore, which are private and therefore forbidden.

You need to work out what is generating the 403, Apache or mod_python.

Graham

2010/1/6 Doug Epling <[email protected]>:
> Why would I want to import apache, util?  The request object created by the
> publisher automatically creates a FieldStorage object.  So when I pass the
> request object, whether POST or GET, along with some other trivial data the
> python script on the server should simply take the data argument as a
> parameter and return a page with it printed on it.  Why doesn't the apache
> user have this permission?
>
> calling page:
>
> def index():
>    s = """\
> <html>
> <head></head>
> <body>
> <h2>Hello World!</h2>
>
> <form action="script/greet" method="GET">
>    Name: <input type="text" name="name"><br>
> <input type="submit">
> </form>
>
> </body>
> </html>
> """
>    return s
>
> server script:
>
> def greet(req, name):
>
>    return 'Hello %s' % name
>
> On 01/05/2010 09:40 PM, john burke wrote:
>>
>> this should be all you really need. what you do with the data from
>> request_data is your own business.
>>
>> from mod_python import apache, util
>>
>> def login(req):
>>
>>   request_data = util.FieldStorage(req)
>>
>>   logreqdata(req, request_data)
>>
>>   qry = "SELECT u.user_id as id, u.user_name as name FROM users u"
>>   qry += " WHERE u.user_name = '"
>>   qry += request_data.getfirst("user_name")
>>   qry += "' AND u.user_pass ='"
>>   qry += request_data.getfirst("user_pass")
>>   qry += "'"
>>   return dorequest(req, qry, "users", "user").toxml("utf-8")
>>
>> def logreqdata(req, data):
>>
>>   if (DEBUG>  0):
>>
>>
>> apache.log_error("********************************************************")
>>     apache.log_error(str(req.parsed_uri))
>>     apache.log_error(str(data))
>>
>> in this case you can imagine that the the dorequest method knows how to
>> query a database (eg. some database is also imported), and that in this
>> instance it returns xml of the form:
>>
>> <users>
>> <user>
>> <id>1</id>
>> <name>john smith</name>
>> </user>
>> </users>
>>
>> unless it doesn't find the user, in which case it returns an error. the
>> logrequestdata function logs the url that was called and the data it was
>> passed. it might look like this:
>>
>> [Sun Sep 20 13:25:37 2009] [error]
>> ********************************************************
>> [Sun Sep 20 13:25:37 2009] [error] (None, None, None, None, None, None,
>> '/site/python/site.py/login', 'user_name=user&user_pass=pass', None)
>> [Sun Sep 20 13:25:37 2009] [error] {'user_name': [Field('user_name',
>> 'user')], 'user_pass': [Field('user_pass', 'pass')]}
>>
>> based on this information you should be able to determine the proper url
>> to call and process the passed data.
>>
>> good luck
>>
>> john
>>
>>
>> Doug Epling wrote:
>>
>>>
>>> Sorry, but I really need a boost here.  I might be dense, but I can
>>> not get a 'script.py' file with a greet(req, name) function to accept
>>> either POST or GET arguments.  I am getting a 403 Forbidden server
>>> error.  Where might I read about server side parameters?
>>>
>>> Thanks.
>>>
>>> Graham
>>>  From james at sindacio.us  Fri Nov 13 02:45:00 2009
>>> From: james at sindacio.us (James Newton)
>>> Date: Fri Nov 13 02:45:10 2009
>>> Subject: [mod_python] POST example?
>>> In-Reply-To:
>>> <c2f9e3c20911122342g58179609s1bb0046b24ac6240-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> References:<c2f9e3c20911122342g58179609s1bb0046b24ac6240-JsoAwUIsXounXO2b/[email protected]>
>>> Message-ID:<c2f9e3c20911122345i3812ac58qc69974240f980a65-JsoAwUIsXounXO2b/[email protected]>
>>>
>>> Hi,
>>>
>>> After looking around I can't seem to find a really straight forward
>>> example
>>> of how to POST, all I can seem to figure out is GET. Currently I'm
>>> trying to
>>> figure this out so I can post to a page with curl, rather then post via a
>>> form, after asking around and getting turned away with "don't use
>>> mod_python" on most occasions, I was hoping someone on this list could
>>> give
>>> me an example of how to post/store post data.
>>>
>>> Thanks,
>>> James Newton
>>> -------------- next part --------------
>>> An HTML attachment was scrubbed...
>>> URL:
>>>
>>> http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20091113/8048f618/attachment.html
>>>
>>>  From graham.dumpleton at gmail.com  Fri Nov 13 04:26:17 2009
>>> From: graham.dumpleton at gmail.com (Graham Dumpleton)
>>> Date: Fri Nov 13 04:26:26 2009
>>> Subject: [mod_python] POST example?
>>> In-Reply-To:
>>> <c2f9e3c20911122345i3812ac58qc69974240f980a65-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> References:<c2f9e3c20911122342g58179609s1bb0046b24ac6240-JsoAwUIsXounXO2b/[email protected]>
>>> <c2f9e3c20911122345i3812ac58qc69974240f980a65-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> Message-ID:<88e286470911130126m21222b57v8270616a602069ce-JsoAwUIsXounXO2b/[email protected]>
>>>
>>> Read:
>>>
>>>   http://webpython.codepoint.net/mod_python_tutorial
>>>
>>> First result for Google on 'mod_python tutorial'.
>>>
>>> Graham
>>>
>>> 2009/11/13 James Newton<[email protected]>:
>>>
>>>>
>>>> Hi,
>>>> After looking around I can't seem to find a really straight forward
>>>>
>>>
>>> example
>>>
>>>>
>>>> of how to POST, all I can seem to figure out is GET. Currently I'm
>>>>
>>>
>>> trying to
>>>
>>>>
>>>> figure this out so I can post to a page with curl, rather then post
>>>>
>>>
>>> via a
>>>
>>>>
>>>> form, after asking around and getting turned away with "don't use
>>>> mod_python" on most occasions, I was hoping someone on this list
>>>>
>>>
>>> could give
>>>
>>>>
>>>> me an example of how to post/store post data.
>>>> Thanks,
>>>> James Newton
>>>>
>>>> _______________________________________________
>>>> Mod_python mailing list
>>>> [email protected]
>>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>>>
>>>>
>>>>
>>>
>>>  From clodoaldo.pinto.neto at gmail.com  Fri Nov 13 05:56:08 2009
>>> From: clodoaldo.pinto.neto at gmail.com (Clodoaldo Neto)
>>> Date: Fri Nov 13 05:56:12 2009
>>> Subject: Fwd: [mod_python] POST example?
>>> In-Reply-To:
>>> <a595de7a0911130107y1067a22exd498225e8aa4baf3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> References:<c2f9e3c20911122342g58179609s1bb0046b24ac6240-JsoAwUIsXounXO2b/[email protected]>
>>> <c2f9e3c20911122345i3812ac58qc69974240f980a65-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> <a595de7a0911130107y1067a22exd498225e8aa4baf3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> Message-ID:<a595de7a0911130256i78bb0c99yce88dcbdca1c959f-JsoAwUIsXounXO2b/[email protected]>
>>>
>>> Forgot to post to the list.
>>>
>>> Clodoaldo
>>>
>>> ---------- Forwarded message ----------
>>> From: Clodoaldo Neto<[email protected]>
>>> Date: 2009/11/13
>>> Subject: Re: [mod_python] POST example?
>>> To: James Newton<[email protected]>
>>>
>>>
>>> 2009/11/13 James Newton<[email protected]>:
>>>
>>>>
>>>> Hi,
>>>> After looking around I can't seem to find a really straight forward
>>>>
>>>
>>> example
>>>
>>>>
>>>> of how to POST, all I can seem to figure out is GET. Currently I'm
>>>>
>>>
>>> trying to
>>>
>>>>
>>>> figure this out so I can post to a page with curl, rather then post
>>>>
>>>
>>> via a
>>>
>>>>
>>>> form, after asking around and getting turned away with "don't use
>>>> mod_python" on most occasions, I was hoping someone on this list
>>>>
>>>
>>> could give
>>>
>>>>
>>>> me an example of how to post/store post data.
>>>>
>>>
>>> You mean you can read data posted by an html form and can't do it when
>>> it is posted by curl? If so show what is your curl code.
>>>
>>> If what you are looking for is how to read data posted by any means read:
>>>
>>> http://webpython.codepoint.net/mod_python_tutorial
>>>
>>> Regards, Clodoaldo
>>>
>>>
>>>>
>>>> Thanks,
>>>> James Newton
>>>>
>>>> _______________________________________________
>>>> Mod_python mailing list
>>>> [email protected]
>>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>>>
>>>>
>>>>
>>>
>>>  From clodoaldo.pinto.neto at gmail.com  Fri Nov 13 05:56:23 2009
>>> From: clodoaldo.pinto.neto at gmail.com (Clodoaldo Neto)
>>> Date: Fri Nov 13 05:56:25 2009
>>> Subject: Fwd: [mod_python] POST example?
>>> In-Reply-To:
>>> <c2f9e3c20911130153y4f16535bg2759654e7cf92c86-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> References:<c2f9e3c20911122342g58179609s1bb0046b24ac6240-JsoAwUIsXounXO2b/[email protected]>
>>> <c2f9e3c20911122345i3812ac58qc69974240f980a65-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> <a595de7a0911130107y1067a22exd498225e8aa4baf3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> <c2f9e3c20911130153y4f16535bg2759654e7cf92c86-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>>> Message-ID:<a595de7a0911130256i6c82a8c4o1dfb199726e12a73-JsoAwUIsXounXO2b/[email protected]>
>>>
>>> ---------- Forwarded message ----------
>>> From: James Newton<[email protected]>
>>> Date: 2009/11/13
>>> Subject: Re: [mod_python] POST example?
>>> To: [email protected]
>>>
>>>
>>> I may be misunderstanding it, I'm assuming POST and GET are handled
>>> the exact same way? The curl command would be like so: curl -F
>>> 'postvar=<-' http://url.tld/. I used the example on that website for a
>>> get var, but using it for post just created another get? I may not
>>> being reading into this right.
>>> James
>>>
>>> On Fri, Nov 13, 2009 at 3:07 AM, Clodoaldo Neto
>>> <[email protected]>  wrote:
>>>
>>>>
>>>> 2009/11/13 James Newton<[email protected]>:
>>>>
>>>>>
>>>>> Hi,
>>>>> After looking around I can't seem to find a really straight
>>>>>
>>>
>>> forward example
>>>
>>>>>
>>>>> of how to POST, all I can seem to figure out is GET. Currently I'm
>>>>>
>>>
>>> trying to
>>>
>>>>>
>>>>> figure this out so I can post to a page with curl, rather then
>>>>>
>>>
>>> post via a
>>>
>>>>>
>>>>> form, after asking around and getting turned away with "don't use
>>>>> mod_python" on most occasions, I was hoping someone on this list
>>>>>
>>>
>>> could give
>>>
>>>>>
>>>>> me an example of how to post/store post data.
>>>>>
>>>>
>>>> You mean you can read data posted by an html form and can't do it when
>>>> it is posted by curl? If so show what is your curl code.
>>>>
>>>> If what you are looking for is how to read data posted by any means
>>>>
>>>
>>> read:
>>>
>>>>
>>>> http://webpython.codepoint.net/mod_python_tutorial
>>>>
>>>> Regards, Clodoaldo
>>>>
>>>>
>>>>>
>>>>> Thanks,
>>>>> James Newton
>>>>>
>>>>> _______________________________________________
>>>>> Mod_python mailing list
>>>>> [email protected]
>>>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>>>>
>>>>>
>>>>>
>>>
>>> _______________________________________________
>>> Mod_python mailing list
>>> [email protected]
>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> Mod_python mailing list
> [email protected]
> http://mailman.modpython.org/mailman/listinfo/mod_python
>