[Twisted-Python] Utilizing Twisted for transport w/ SUDS

Alexandre Quessy alexandre at quessy.net
Tue Apr 20 02:48:22 EDT 2010

Hi everyone,
Two years ago, I've dropped SUDS to generate and parse the XML by
hand, using xml.dom.minidom.
I don't remember why exactly.
I hope this comment is useful for you. (?!)



2010/4/19 jathan. <jathan at gmail.com>:
> Hello-
> I have a project that is based on Twisted used to
> communicate with network devices and I am adding support for a new
> vendor (Citrix NetScaler) whose API is SOAP.  Unfortunately the
> support for SOAP in Twisted still relies on SOAPpy, which is badly out
> of date. In fact as of this email (I just checked), twisted.web.soap
> itself hasn't even been updated in 21 months!
> I would like to ask if anyone has any experience they would be willing
> to share with utilizing Twisted's superb asynchronous transport
> functionality with SUDS.  It seems like plugging in a custom Twisted
> transport would be a natural fit in SUDS' Client.options.transport, I'm just
> having
> a hard time wrapping my head around it.
> I did come up with a way to call the SOAP method with SUDS
> asynchronously by utilizing twisted.internet.threads.deferToThread(),
> but this feels like a hack to me.
> Here is an example of what I've done, just to give you an idea:
>    # netscaler is a module I wrote using suds to interface with NetScaler
>    # Source: http://bitbucket.org/jathanism/netscaler-api/src
>    import netscaler
>    import os, sys
>    from twisted.internet import reactor, defer, threads
>    # netscaler.API is the class that sets up the suds.client.Client object
>    host = 'netscaler.local'
>    username = password = 'nsroot'
>    wsdl_url = 'file://' + os.path.join(os.getcwd(), 'NSUserAdmin.wsdl')
>    api = netscaler.API(host, username=username, password=password,
> wsdl_url=wsdl_url)
>    results = []
>    errors = []
>    def handleResult(result):
>        print '\tgot result: %s' % (result,)
>        results.append(result)
>    def handleError(err):
>        sys.stderr.write('\tgot failure: %s' % (err,))
>        errors.append(err)
>    # this converts the api.login() call to a Twisted thread.
>    # api.login() is equivalent to:
>    # api.service.login(username=self.username, password=self.password)
>    deferred = threads.deferToThread(api.login)
>    deferred.addCallbacks(handleResult, handleError)
>    reactor.run()
> This works as expected and defers return of the api.login() call until
> it is complete, instead of blocking.  But as I said, it doesn't feel
> right.
> Thanks in advance for any help, guidance, feedback, criticism,
> insults, or total solutions.
> jathan.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Alexandre Quessy

More information about the Twisted-Python mailing list