Hack Forums
[Python] Read Xml and make post request - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Read Xml and make post request (/showthread.php?tid=5872937)



Read Xml and make post request - Ownc0d3r - Aug 12, 2018

Hey,

I'm trying to make a python script that accesses a server see the response from the server and use that response to make Post request.
The response is in XML and I need to make multiple post requests with the values between tags.
Any library or recommendation?

Example:

Code
#!/usr/bin/env python

import requests

i = 1

while True:
   bucket = requests.get("https://server.com/")
   print (bucket.text.encode('ISO-8859-1'))
   print (len(bucket.content))
   r = requests.post("http://server.com", data={'number': 12524, 'type': 'issue', 'action': 'show'})
   i = i + 1
   if(i > 100):
       break

input('Press ENTER to exit')



RE: Read Xml and make post request - TyrantKingBen - Aug 12, 2018

(Aug 12, 2018 06:00 AM)Ownc0d3r Wrote:  Hey,

I'm trying to make a python script that accesses a server see the response from the server and use that response to make Post request.
The response is in XML and I need to make multiple post requests with the values between tags.
Any library or recommendation?

Example:

Code
#!/usr/bin/env python

import requests

i = 1

while True:
   bucket = requests.get("https://server.com/")
   print (bucket.text.encode('ISO-8859-1'))
   print (len(bucket.content))
   r = requests.post("http://server.com", data={'number': 12524, 'type': 'issue', 'action': 'show'})
   i = i + 1
   if(i > 100):
       break

input('Press ENTER to exit')

Use ElementTree from the xml module. https://docs.python.org/3/library/xml.etree.elementtree.html

ElementTree has a fromstring method that you can pass the XML response from the GET request. Is this for an S3 bucket?


RE: Read Xml and make post request - Ownc0d3r - Aug 12, 2018

(Aug 12, 2018 06:23 AM)TyrantKingBen Wrote:  Use ElementTree from the xml module. https://docs.python.org/3/library/xml.etree.elementtree.html

ElementTree has a fromstring method that you can pass the XML response from the GET request. Is this for an S3 bucket?

Yes, it is for S3 bucket! I'm going to check it out


RE: Read Xml and make post request - TyrantKingBen - Aug 12, 2018

(Aug 12, 2018 06:33 AM)Ownc0d3r Wrote:  Yes, it is for S3 bucket! I'm going to check it out

I've used it for parsing the ListBucketResult object. It should be pretty straightforward to implement for any of the S3 API endpoints, but there is something called Boto 3 (https://boto3.readthedocs.io/en/latest/guide/quickstart.html) that you might look into if you are going to be hitting a lot of different endpoints. I haven't used it personally, but it has a lot of good documentation.