I am working with Tornado and SUDS. I would like to make an asynchronous call using Tornados AsyncHTTPClient. Here is my code
class RequestHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def post(self):
data = tornado.escape.json_decode(self.request.body)
uuid = data['id']
suds_client = Client(wsdl_location, nosend=True)
context = suds_client.service.GetSubscriptions(uuid)
tornado_client = tornado.httpclient.AsyncHTTPClient()
tornado_client.fetch(context.envelope,callback=self.on_response)
def on_response(self,response):
print response
#self.write(str(response))
self.finish()
I set nosend = True in the above code based on the discussion from the post here
It says to set nosend = True and it builds an envelope and then use Tornado asynchronous http agent to fetch it.
When I execute the above code I don't get any response. How do I do it? Any help would be appreciated.Thanks.
I solved it myself. I will be providing my code below for reference and understanding.
class RequestHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def post(self):
data = tornado.escape.json_decode(self.request.body)
uuid = data['id']
suds_client = Client(wsdl_location, transport = trans_certs, nosend=True)
context = suds_client.service.GetSubscriptions(uuid)
tornado_client = tornado.httpclient.AsyncHTTPClient()
url=context.client.location()
tornado_client.fetch(url,body=str(context.envelope),method="POST",headers=context.client.headers(),callback=self.on_response)
def on_response(self,response):
result=str(response.body)
dom1 = parseString(result)
for node in dom1.getElementsByTagName('subscriptionId'):
self.write(str(node.toxml()))
self.finish()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With