(Fwd) Re: [mod_python] How to pass values

export at hope.cz export at hope.cz
Sat Jan 27 04:01:03 EST 2007


 Graham,
Thank you for your reply.
So, I used the debugging  techniques like this:

in input filter
###########################
from mod_python import apache,Cookie
def inputfilter(filter):
	filter.req.log_error('Running inputfilter')
	filter.req.log_error('Setting myflag..')
	filter.req.myflag = True
	filter.req.log_error('myflag was set to:')
	filter.req.log_error(`filter.req.myflag`)
	if filter.req.method != 'POST':
		filter.pass_on()
		return
	s = filter.read()
	while s:
		f.write(s)
		f.flush()
		filter.write(s)
		filter.flush()
		s = filter.read()
		
	if s is None:
		filter.close()
		f.close()
########################

in handler 
##########################
   
def handler(req):
     if req.method == 'GET':
	......

    else:
	if  req.method == 'POST':
	 	req.log_error('Myhandler')
		req.log_error('MyHandler, in POST request, has myflag')
		req.log_error(`req.myflag`)
	....
	....
#######################
and here is a part of error log

..
[Sat Jan 27 09:48:54 2007] [notice] Child 2196: Starting thread to listen on port 80.
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] Running inputfilter
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] Setting myflag..
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] myflag was set to:
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] True
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] Running inputfilter
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] Setting myflag..
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] myflag was set to:
[Sat Jan 27 09:49:05 2007] [error] [client 127.0.0.1] True
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] Running inputfilter
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] Setting myflag..
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] myflag was set to:
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] True
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] Running inputfilter
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] Setting myflag..
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] myflag was set to:
[Sat Jan 27 09:49:08 2007] [error] [client 127.0.0.1] True
[Sat Jan 27 09:49:12 2007] [error] [client 127.0.0.1] Myhandler, referer: 
http://127.0.0.1/mod/uploadvideo.py?17644
[Sat Jan 27 09:49:12 2007] [error] [client 127.0.0.1] MyHandler, in POST request, has myflag, 
referer: http://127.0.0.1/mod/uploadvideo.py?17644
.....
....
....
[Sat Jan 27 09:49:12 2007] [error] [client 127.0.0.1] AttributeError: 'mp_request' object has no 
attribute 'myflag', referer: http://127.0.0.1/mod/uploadvideo.py?17644
...


Where can be a problem? What shall I try?
Can you see any mistake I make?
Thank you again for help
Lad


> Use some standard debugging techniques yourself to try and work it out.
> 
> On 26/01/2007, at 10:44 PM, export at hope.cz wrote:
> 
> > Graham,
> > Thank you for your reply.
> > I have
> >
> > def inputfilter(filter):
> > filter.req.myflag = True
> 
> Add:
> 
>    filter.req.log_error('inputfilter')
> 
> > ...
> > ...
> >
> > so, as you can see the first command in input filter
> > is filter.req.myflag = True
> > but yet, I can not access the req.myflag
> > in my request handler.
> > When I try
> > req.write(`req.myflag`)
> 
> Add before this:
> 
>    req.log_error('handler')
> 
> In other words, use the logging system to dump information into the  
> Apache
> log files to see if the input filter is actually being called. It  
> would look like it
> isn't. What have you done so far to confirm it is?
> 
> Graham
> 
> > I will receive the same error:
> >
> > AttributeError: 'mp_request' object has no attribute 'myflag'
> >
> > What shall I try to solve the problem. Do you have any idea?
> > Thank you
> > Lad
> >
> >> Your input filter can't have been called then, or not the part  
> >> where you
> >> assigned the attribute. If the variable may not be there in all
> >> situations,
> >> then use:
> >>
> >> if hasattr(req, 'myflag'):
> >> if req.myflag:
> >> ..
> >>
> >> Graham
> >>
> >> On 26/01/2007, at 7:09 PM, export at hope.cz wrote:
> >>
> >>> Graham ,
> >>> Thank you for your reply and help.
> >>> I tried the way you suggested but I received the error
> >>>
> >>> AttributeError: 'mp_request' object has no attribute 'myflag'
> >>>
> >>> Can you please help?
> >>> Thank you
> >>> Lad.
> >>>
> >>>
> >>>>
> >>>> On 26/01/2007, at 2:45 AM, export at hope.cz wrote:
> >>>>
> >>>>> Depending on a value being calculated in input filter,
> >>>>> I will have to make a decission in request handler.
> >>>>> What is a way to find out the value of the variable from input
> >>>>> filter in request handler?
> >>>>
> >>>> I believe this was mentioned before.
> >>>>
> >>>> In filter, set an attribute on the request object:
> >>>>
> >>>> def inputfilter(filter):
> >>>> ...
> >>>> filter.req.myflag = True
> >>>> ...
> >>>>
> >>>> In the request handler, you can then access that variable.
> >>>>
> >>>> def handler(req):
> >>>> ...
> >>>> if req.myflag:
> >>>> ...
> >>>> ...
> >>>>
> >>>> Graham
> >>>
> >>
> >>
> >
> >
> > ------- End of forwarded message -------




More information about the Mod_python mailing list