[Python-Dev] How to set/update value in a xml file using requests in python

2018-02-08 Thread Sum J
My xml file is located in local network:

http://192.168.43.109/DevMgmt/NetAppsDyn.xml

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






off




I want to set the value for 'ResourceUI' and 'Port' field in above xml.

I have used below code :

 import requests
 data = {
  'ResourceURI':'web-proxy.xxx.yy.com',
  'Port':8080
}

URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml'

# 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.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] How to set/update value in a xml file using requests in python

2018-02-08 Thread Dan Stromberg
This is more relevant to python-list than python-dev. I've added
python-list to the To header.

Gmail doesn't appear to allow setting a reply-to for a single message,
so I've not set that; please, when replying, drop python-dev from the
to: header.

You'll likely want to set up some kind of REST endpoint to allow
updating your xml file.  Imagine if anyone could change anyone else's
xml files - it'd be pretty chaotic.

Perhaps flask would be appropriate?
http://flask.pocoo.org/docs/0.12/quickstart/

You likely will want a PUT or a POST HTTP verb:
https://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request

HTH.

On Thu, Feb 8, 2018 at 12:38 AM, Sum J  wrote:
> My xml file is located in local network:
>
> http://192.168.43.109/DevMgmt/NetAppsDyn.xml
>
> Below is a part content of above xml I want to update :
>
> 
>
> 
> 
> 
> off
> 
>
> 
>
> I want to set the value for 'ResourceUI' and 'Port' field in above xml.
>
> I have used below code :
>
>  import requests
>  data = {
>   'ResourceURI':'web-proxy.xxx.yy.com',
>   'Port':8080
> }
>
> URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml'
>
> # 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.
>
>
>
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/drsalists%40gmail.com
>
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com