Basically I have this xml element (xml.etree.ElementTree) and I want to POST it to a url. Currently I’m doing something like
xml_string = xml.etree.ElementTree.tostring(my_element)
data = urllib.urlencode({'xml': xml_string})
response = urllib2.urlopen(url, data)
I’m pretty sure that works and all, but was wondering if there is some better practice or way to do it without converting it to a string first.
Thanks!
If this is your own API, I would consider POSTing as
application/xml. The default isapplication/x-www-form-urlencoded, which is meant for HTML form data, not a single XML document.