I’m working with the USPS APIs which are XMLs. I want to be able to pass variables into the XML tree without rebuilding it child by child. How do I do it in Python?
def fixed_xml_body_as_string(dest_zip, origin_zip):
#pass zip codes into XML
return """
https://secure.shippingapis.com/shippingapi.dll?API=RateV4&XML=
<RateV4Request USERID='XXXXXXXXXXX'>
<Revision>2</Revision>
<Package ID="1ST">
<Service>PRIORITY</Service>
<ZipOrigination></ZipOrigination>
<ZipDestination></ZipDestination>
<Pounds>1</Pounds>
<Ounces>0</Ounces>
<Container></Container>
<Width></Width>
<Length></Length>
<Height></Height>
<Girth></Girth>
<Machinable>false</Machinable>
</Package>
</RateV4Request>
"""
I want to dynamically pass the zip codes into the XML.