[Python-Dev] How to set/update value in a xml file using requests in python
Sum J
sjsumitj at gmail.com
Mon Feb 12 04:19:47 EST 2018
Thanks Dan for your response.
I have updated the data to be sent in xml format and now I am able to
update the required fields using put request.
data= '''
<nadyn:NetAppsDyn >
<nadyn:ProxyConfig>
<dd:ResourceURI>web-proxy.xx.com</dd:ResourceURI>
<dd:Port>8080</dd:Port>
<dd:UserName></dd:UserName>
<dd:ProxySupport>on</dd:ProxySupport>
</nadyn:ProxyConfig>
</nadyn:NetAppsDyn>'''
On Thu, Feb 8, 2018 at 10:15 PM, Dan Stromberg <drsalists at gmail.com> wrote:
> 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 <sjsumitj at gmail.com> 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 :
> >
> > <nadyn:NetAppsDyn>
> >
> > <nadyn:ProxyConfig>
> > <dd:ResourceURI/>
> > <dd:Port/>
> > <dd:ProxySupport>off</dd:ProxySupport>
> > </nadyn:ProxyConfig>
> >
> > </nadyn:NetAppsDyn>
> >
> > 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
> > Python-Dev at python.org
> > https://mail.python.org/mailman/listinfo/python-dev
> > Unsubscribe:
> > https://mail.python.org/mailman/options/python-dev/drsalists%40gmail.com
> >
>
More information about the Python-list
mailing list