xmlrpclib question

Graham Dumpleton grahamd at dscpl.com.au
Mon Jul 22 19:28:15 EDT 2002


Eric Texier <erict at millfilm.co.uk> wrote in message news:<3D3BFA10.92E38B5B at millfilm.co.uk>...
> I posted this question earlier but I am still confuse about what I am
> doing wrong.
> Why, in the class  'clientRootTask'   just taking out the 'if' statement
> will make
> it work:
> 
> 
> .
> .
> if  serverp:
>     serverp.SendTask(msg)
> ..
> produce the error:
>     raise apply(Fault, (), self._stack[0])
> xmlrpclib.Fault: <Fault 1: 'exceptions.Exception:method "__nonzero__"
> is not supported'>

The XML-RPC proxy class defines __getattr__ to intercept all method
calls made against the proxy and translate them into a request against
the remote object on the server. Your "if" statement does the equivalent
of call the __nonzero__ method. What is most likely therefore happening
is that the exception is being raised on the server because the remote
object doesn't have __nonzero__ as a method. This is translated into an
XML-RPC Fault object at the client.

Try writing your code as:

  if type(serverp) is not types.NoneType:
    serverp.SendTask(msg)

Alternatively, the XML-RPC proxy class in xmlrpclib could have provided
the method:

  def __nonzero__(self):
    return 1

If serverp was indeed a None object, it would then fail the "if" test and
the code wouldn't get run. With __nonzero__ above in the XML-RPC proxy, it
would have resolved the test on the actual local proxy object, returning
true and thereby running your code.

Understand?



More information about the Python-list mailing list