This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Send XML file to REST API in Python3

I am trying to interact with a REST API using the requests library.

I need to pass a large XML file to the API - I can do this easily with curl in Linux but I want a pythonic way to do this.

In curl my syntax looks like this:

curl -k 10.244.1.2:4444/.../APIController -F "reqxml=MYxml.xml"

Note: the -k flag just ignores the ssl error

So far here is what I have come up with:

import requests    
url = r'10.244.1.2:4444/.../APIController    
x = open('MYxml.xml', 'r').read()

q = requests.post(url, data=x, verify=False)    
print(q.text)

If I change that q variable to this: q = requests.post(url + x, verify=False) then the command will work. Prepaid Gift Balance However, with longer XML files it will fail. 

I have looked at these two related posts: First, Second but the suggestions look just like my syntax unless I am missing something obvious

Any help is appreciated!



This thread was automatically locked due to age.