[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to set/update value in a xml file using requests in python

My xml file is located in local network :

Below is a part content of above xml I want to update :


I want to set value for 'ResourceUI' and 'Port' field in above xml.
I have used below code :

     data = {

    URL = ''

    # content type
    head = {'Content-type': 'text/xml'}
    # sending get request
    gr= requests.get(url=URL)
    print gr

    # sending put request
    r = requests.put(url=URL, data=data,headers=head)
    print r.status_code
    # extracting response text
    output_xml = r.text
    print("The op xml is:%s" % output_xml)

Issue : The fields are not getting updated in xml using put request. I am able to see the response for get (request) , but for put request it is throwing errror code : 301 , resource has been moved permanently.