Post XML file using Python

python, xml

Solution

If you need to send XML I would recommend that you take a look at requests. It allows you to easily send data using POST requests.

You should be able to transmit the XML data directly from your Python code using requests.

xml = """my xml"""
headers = {'Content-Type': 'application/xml'}
requests.post('http://www.my-website.net/xml', data=xml, headers=headers)

You could also load the xml from a text-file and send that, if you don't want to have the xml document hard-coded.

Problem

I'm new to Python and in need of some help. My aim is to send some XML with a post request to a URL, which is going to trigger a SMS being sent. I have a small XML document that I want to post to the URL. Can I reference the XML document on my server in the python code that needs posting, or do I include the XML data to be sent in the actual python code. Can any help me out with an example?

Original source

Related problems