xmlrpclib - using getattr on a python xmlrpc proxy -
this answer implies can use getattr on xmlrpc server proxy. however, in case doesn't seem work. missing step in definition of server?
my server code this:
import simplexmlrpcserver class listener(object): def ping(self): return "ping" s = simplexmlrpcserver.simplexmlrpcserver(("localhost",8910), allow_none=true) l = listener() s.register_instance(l) s.register_introspection_functions() s.serve_forever() when use interactively can call ping function, can't use getattr on proxy:
$ python -i activepython 2.7.2.5 (activestate software inc.) based on python 2.7.2 (default, jun 24 2011, 12:22:14) [msc v.1500 64 bit (amd64)] on win32 type "help", "copyright", "credits" or "license" more information. >>> import xmlrpclib >>> proxy = xmlrpclib.serverproxy("http://localhost:8910", allow_none=true) >>> proxy.ping() 'ping' >>> getattr(proxy, "ping") traceback (most recent call last): file "<stdin>", line 1, in <module> file "c:\python27\lib\xmlrpclib.py", line 1224, in __call__ return self.__send(self.__name, args) file "c:\python27\lib\xmlrpclib.py", line 1575, in __request verbose=self.__verbose file "c:\python27\lib\xmlrpclib.py", line 1264, in request return self.single_request(host, handler, request_body, verbose) file "c:\python27\lib\xmlrpclib.py", line 1297, in single_request return self.parse_response(response) file "c:\python27\lib\xmlrpclib.py", line 1473, in parse_response return u.close() file "c:\python27\lib\xmlrpclib.py", line 793, in close raise fault(**self._stack[0]) xmlrpclib.fault: <fault 1: '<type \'exceptions.exception\'>:method "ping.__repr__" not supported'> >>>
it not work way in interactive console. console wants show repr of function trying call ping.__repr__ fails.
assigning variable works:
>>> f = getattr(proxy, 'ping') >>> f() 'ping'
Comments
Post a Comment