Creating and Posting XML with Python

Python
2021-10-10 18:45 (3 years ago) ytyng

Create and Post XML with Python

from xml.etree import ElementTree

request_xml = ElementTree.Element('request')
update_request = ElementTree.SubElement(
    request_xml, 'itemUpdateRequest')
item = ElementTree.SubElement(update_request, 'item')
ElementTree.SubElement(item, 'itemUrl').text = itemUrl

for key, value in updateData.items():
ElementTree.SubElement(item, key).text = value response = self.request( '/es/1.0/item/update', method='post', headers={'Content-Type': 'application/xml'}, data=ElementTree.tostring( request_xml, encoding='utf-8', xml_declaration=True) )
Current rating: 5

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011