Well, I just looked at him; my old method is suck because xmlrpclib.ServerProxy try to connect to the XmlRPC server when you call the method, not before !!!
Try this instead:
import xmlrpclib import socket def _get_rpc(): a = xmlrpclib.ServerProxy('http://dd: LNXFhcZnYshy5mKyOFfy@127.0.0.1 :9001') try: a._()
To summarize this, we have 3 cases:
An XmlRPC server is inserted, and in it we have defined a method called _ () :
( EDIT : I chose the name _ because it is unlikely to have a method with that name, but this case can still happen)
In this case, the exception will not catch, and the code will be executed return True
The XmlRPC server is started, and in it we do not have a method controlled by the _ () method:
This time xmlrpclib.Fault will be raised and we will also move on to return True
XmlRPC server does not work :
Now the socket.error exception will be raised and that when we call a._() , so we must return False
I donβt know if there is an easy way to do this, and I will love to see it until then, hope this can fix it this time :)
NB: when you do if a: python will again look for the __nonzero__() method to check the boolean value of a , and that will fail.
NB 2: Some xmlrpc services offer an authentication-specific rpc path, along with service delivery methods such as login () ..., this method can replace the _ () method in our case, so just call login () will be enough to find out whether the service (socket.error) is up or down, and at the same time, this login () method authenticates the user if the service is completed.
mouad source share