[mod_python] Re: Access-Handler based on a Variable

Christian Klinger cklinger at novareto.de
Mon Aug 6 05:51:38 EDT 2007


Graham Dumpleton schrieb:
> On 06/08/07, Christian Klinger <cklinger at novareto.de> wrote:
>> Hi mod_python Users,
>>
>> i am new to mod_python so sorry for stupid questions.
>>
>>
>> I try to write an access handler for an xml-rpc connection.
>> The access handler should check if a key in the xml-rpc
>> data is correct.
>>
>> Here my questions:
>> Is this possible with mod_python?
>> Has anyone an example?
>> How can i access the (12) of getResults in the accesshandler.
>>
>>
>> Christian
>>
>> Here is my code:
>> --------------------------------------------------------
>> <VirtualHost *:80>
>>      ServerName dummy-host.example.com
>>      ServerAlias www.dummy-host.example.com
>>
>>     <Proxy *>
>>        AuthBasicAuthoritative Off
>>         AddHandler mod_python .py
>>         PythonHandler myscript.py
>>         PythonAccessHandler myscript
>>         PythonDebug On
>>         PythonEnablePdb On
>>       </Proxy>
>>
>>          RewriteEngine On
>>          RewriteRule ^/(.*)
>> http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/extraNet/VirtualHostRoot/$1
>> [L,P]
>>
>> </VirtualHost>
>>
>>
>> myscript.py
>> def accesshandler(req):
>>      apache.log_error("accesshandler -%s" %req)
>>      if key == "OK"
>>          return apache.OK
>>      return
>>
>>
>> the client:
>> portal = xmlrpclib.Server('http://192.168.2.23/extraNet')
>> print portal
>> print portal.getResult(12)
> 
> An access handler or other handler phase prior to the actual content
> handler should not as a rule be consuming the request content. If this
> is done, it can cause problems when certain features of Apache are
> being used.
> 
> All I can suggest is not to use an access handler, but instead use a
> stacked content handler.
> 
>          PythonHandler myscript::prehandler myscript::handler
> 
> The prehandler could decode the actual XML-RPC request and check for
> any required parameters it may pass. If the required parameter is
> missing it should return the appropriate error status, otherwise it
> would store the decoded request content as req.data and return
> apache.DECLINED as the result. Provide apache.DECLINED is returned as
> the result, the real handler would then still be called and it can
> access the decode request from the prehandler as req.data.
> 
> Graham
Hi Graham,

i try to use an apache as a proxy for the real web-server.
I want only allow users with a valid key to access the service.

Maybe i can use an Authenhandler or Authzhandler?

Now i use this script:

def accesshandler(req):
     #import pdb; pdb.set_trace()
     data = req.read()
     apache.log_error("accesshandler %s" %len(data))
     if data != '':
         key = xmlrpclib.loads(data)[0][0]
     #key = xmlrpclib.loads(data)[0][1]
         apache.log_error("accesshandler %s" %key)
     return apache.OK

In the error_log i see the right key.

But the client gives me this traceback (unfortunatly i do not see
something in the apache error_log:

haubitz:~/Scripts/rpc chrissi$ python2.3 client.py
Traceback (most recent call last):
   File "client.py", line 53, in ?
     portal.getResult('gustav')
   File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/xmlrpclib.py", 
line 1032, in __call__
     return self.__send(self.__name, args)
   File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/xmlrpclib.py", 
line 1319, in __request
     verbose=self.__verbose
   File 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/xmlrpclib.py", 
line 1073, in request
     headers
xmlrpclib.ProtocolError: <ProtocolError for 192.168.2.23/extraNet: 500 
Internal Server Error>


Christian



More information about the Mod_python mailing list