Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of methods for xmlrpclib.ServerProxy() without using dir()?

Tags:

python

methods

I can not get a list of methods on xmlrpclib.ServerProxy(). I have tried using dir(); however, the interpreter keeps returning an error.

This is what I tried:

>>>s = xmlrpclib.ServerProxy("http://192.168.1.72:8888")
>>>dir(s)

And I get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
 return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
 verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
 return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
 return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
 return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 793, in close
 raise Fault(**self._stack[0])

xmlrpclib.Fault: <Fault 1: '<type \'exceptions.Exception\'>:method "__dir__" is not supported'>

Dir() is not supported, how can I get a list of methods?

like image 551
daiuto Avatar asked Oct 16 '25 01:10

daiuto


2 Answers

I might be wrong, but I suspect what you're really after is the methods supported by the remote system which will be proxied (on-demand) to the local object.

If the server supports the XML introspection API, you can use the ServerProxy.system.listMethods() method...

>>> s = xmlrpclib.ServerProxy("http://192.168.1.72:8888")
>>> s.system.listMethods()
like image 147
Aya Avatar answered Oct 18 '25 16:10

Aya


>>> import xmlrpclib
>>> dir (xmlrpclib.ServerProxy)
['_ServerProxy__close', '_ServerProxy__request', '__call__', '__doc__', '__getattr__', '__init__', '__module__', '__repr__', '__str__']

This what you're after?

According to the docs when you pass dir an instance of an object, it looks for a method in that object called __dir__ and returns the results of calling that method on the object. Since ServerProxy does not implement __dir__, you have to call it on the class object to get a list of it's attributes.

EDIT: Since you're actually looking for methods on the remote system this answer is now kind of useless, but I think I'll leave it here as a reference for anyone stumbling across this question.

like image 25
Brian Avatar answered Oct 18 '25 17:10

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!