Python で XML を作って Post する

Posted by: ytyng 7 months, 1 week ago

Python で XML を作って Post する

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

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