On Jul 06, 2009 at 18:22, Juha Heinanen <jh(a)tutpro.com> wrote:
[...]
when i try domain.reload with xmlrpc module, it hangs
and ngrep reports:
[...]
one difference that could explain the hangup is that
xmlrpc module does
not close the connection like mi_xmlrpc server does.
You are right, it's the close. Looks like the default behaviour of
xmlrpclib is totally broken...
Here's how to make it work
(code ripped from ser_ctl : serctl/sercmlrpc.py --
http://git.sip-router.org/cgi-bin/gitweb.cgi?p=ser;a=blob;f=ser_ctl/serctl/…
)
---------------------------------------------------------------------------
import xmlrpclib, httplib
XMLRPC_SERVER = "127.0.0.1"
XMLRPC_PORT = 5060
class Transport:
def __init__(self):
self.conn=httplib.HTTPConnection(XMLRPC_SERVER, str(XMLRPC_PORT));
def _http_request(self, uripath, body, host):
self.conn.request("POST", uripath, body, {})
def request(self, host, uripath, body, verbose=0):
self._http_request(uripath, body, host)
response=self.conn.getresponse()
if response.status != 200:
raise xmlrpclib.ProtocolError(host+uripath, response.status,
response.reason, response.msg)
data=response.read()
parser, unmarshaller=xmlrpclib.getparser()
parser.feed(data)
parser.close()
return unmarshaller.close()
transport=Transport()
c=xmlrpclib.ServerProxy("http://" + XMLRPC_SERVER+ ":" +
str(XMLRPC_PORT),
transport)
res=c.core.pwd()
print res;
---------------------------------------------------------------------------
Note: the code in ser_ctl is much more complex, it supports authentication
and https, I reduced it to the basics for this example.
We could also close the connection in sr, but that would require additional
code and it's the xmlrpc lib that's broken (parsing the answer only on close()
is really braindamaged). However if there are lots of applications
relying on the broken behaviour, I might be convinced to add the close
option in sr xmlrpc.
Andrei