[Twisted-Python] call XMLRPC
joel tremblet
bingopitts at gmail.com
Tue Apr 17 23:39:40 EDT 2012
Thank for your help
It's right, the code number 1 is not well structured that is the reason I
modified it for the code number 2
But in the first one the xml_rpc call retun the good answer and in the
second one I received a error message
I tried your code,this is a better structure (The Class Resource is in the
next example in the book)
But the code doesn't work, I have the same error message about xml_rpc
answer
[Failure instance: Traceback: <class 'xmlrpclib.Fault'>: <Fault -32602:
'server error. invalid method parameters'>
C:\python27\lib\site-packages\twisted\internet\posixbase.py:263:_disconnectSelectable
C:\python27\lib\site-packages\twisted\internet\tcp.py:433:connectionLost
C:\python27\lib\site-packages\twisted\internet\tcp.py:277:connectionLost
C:\python27\lib\site-packages\twisted\web\xmlrpc.py:373:connectionLost
--- <exception caught here> ---
C:\python27\lib\site-packages\twisted\web\xmlrpc.py:444:parseResponse
C:\python27\lib\xmlrpclib.py:1137:loads
C:\python27\lib\xmlrpclib.py:793:close
]
The issue is how to call xml_rpc callRemote correctly ?
Thank again
Le 17 avril 2012 04:46, Phil Mayers <p.mayers at imperial.ac.uk> a écrit :
> On 04/17/2012 03:38 AM, joel tremblet wrote:
>
> > I try to declare the Proxy(OF_XMLRPC_URL) differently, without success
> >
> > Where is my mistake ....
>
> That code is all wrong, and (to be blunt) pretty horrible too.
>
> Why have you re-implemented a HTTP protocol yourself? You're bound to
> get this wrong (and in fact have, in several ways). Don't do this. Use
> the HTTP stack that comes with Twisted.
>
> Anyway, your major mistake in the 1st example is that, at the end of the
> lineReceived method, you always call the sendResponse() method. This
> happens immediately, before the XMLRPC reply has come back, so your code
> sends "no value". You need to attach the sendResponse method to the
> deferred returned from the xmlrpc call.
>
> I would junk it and start again, like this:
>
> from twisted.web import server, resource, xmlrpc, http
>
> proxy = xmlrpc.Proxy(XMLRPC_URL)
>
> class MyResource(resource.Resource):
> isLeaf = True
> def render_GET(self, request):
> sessid = request.args['sessid'][0]
> keyid = request.args['keyid'][0]
> d = proxy.callRemote('checkCommand', sessid, keyid)
> d.addCallback(self._done, request)
> d.addErrback(self._err, request)
> return server.NOT_DONE_YET
>
> def _done(self, res, request):
> if res!=1:
> request.setResponseCode(406)
> else:
> request.setResponseCode(200)
> request.finish()
>
> def _err(self, failure, request):
> request.setResponseCode(405)
> request.finish()
>
> reactor.listenTCP(8080, server.Site(MyResource()))
> reactor.run()
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120417/953d9977/attachment.htm
More information about the Twisted-Python
mailing list