python - How does tornado post xml data when using AsyncHTTPClient? -


i use tornado 4.2 , need send xml data post request. if use requests library it's working expected:

 r = requests.post(url, headers=headers, data=send_xml, verify=false)  prepay_result_dic = cls.trans_xml_to_dict(r.content) 

how can achieve same functionality tornado.httpclient.asynchttpclient? i've tried:

@tornado.gen.coroutine def post_async_url(url, payload={}, headers={}):     '''     post url,to replace requests lib...     :param url: "http://www.google.com/"     :param payload: {'userid': user_id}     :return: response.body     '''     import urllib     http_client = tornado.httpclient.asynchttpclient()     payload = urllib.urlencode(payload)     response = yield tornado.gen.task(http_client.fetch, url, method="post", headers=headers, body=payload, validate_cert=false)     raise tornado.gen.return(response.body) 

but above code raises error:

typeerror: not valid non-string sequence or mapping object 

this error isn't coming tornado, it's coming urllib.urlencode, , can happen when try call function on string instead of dict. comments indicate payload supposed dict, since question asking xml, payload string instead? if so, can pass directly body of request, without url-encoding it.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -