I have this xml to run the fixlet it works fine with “curl” but with python it spits out the xml error.
I am trying to paste the xml but its not working in this message
Unix Support
1299
Action1
server1
action_xml="action.xml"
r=requests.post(‘https://xyz:52311/api/actions’,auth=('user’, ‘abc’),data=action_xml,verify=False)
print(r.text)
{“format”:“Unexpected server error: {message}”,“arguments”:[“XML parsing error: invalid document structure Line 1, Character 1”]}
same xml works with “curl”
$ curl -k -X POST -d @action.xml -u user:pwd https://abc:52311/api/actions
<?xml version="1.0" encoding="UTF-8"?>
Deploy: Splunk Forwarder 7.0.4 - Linux
1336
looks like your action.xml is a pointer to an XML file. Looks like Python does not like pointing at that file
Relative path to file issue?
File permissions issue?
data=action_xml is that supposed to be an underscore instead of a dot?
I am not a python-head, so those are my best guesses at where to look next for solution.
Its variable with full path… Permission are ok.
action_xml="/home/python_scripts/action.xml"
I have to do run the post in this way. Then it works.
from lxml import etree
action_xml="/home/python_scripts/action.xml"
xml=""
parser = etree.XMLParser(remove_blank_text=True)
xml_tree= etree.parse(action_xml,parser)
xml_tree.write(action_xml,pretty_print=True)
with open(action_xml) as xml:
r=requests.post(‘https://xyz:52311/api/actions’,auth=('user’, ‘abc’),data=xml,verify=False)
print(r.text)
1 Like
Sorry to be late on reply. Glad you solved. Looks like it was an xml conversion or hygiene or encoding issue at the end (Hence the XML Parser and pretty print?)
Thank you for posting the solve to help future knowledge seekers!