0

I am creating a program in python that posts an XML file to a website's rest API to create a VCS root (this is what the website API documentation suggests). My program creates an XML file, based on user input, posts it (using the requests library), then deletes the file. Is there a way I can post the information contained in the XML file (mostly property values), without creating and deleting this temporary XML file? Can I post the information as a string or something? Examples in python or cURL could help.

2
  • use the data-attribute of requests. Commented Aug 23, 2016 at 21:23
  • @Daniel do you know where I can find some examples? Commented Aug 24, 2016 at 20:14

1 Answer 1

1

Use the data-Attribute of requests:

from io import BytesIO
import xml.etree.ElementTree as et

data = et.Element('some-xml')
tree = et.ElementTree(data)
payload = BytesIO()
tree.write(payload)
r = requests.post(url, data=payload.getvalue())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.