How to send xml request and get xml response in Python?

I am currently using WS, where I send an XML request to a URL and then get an XML response. The request may look like this:

<RequestColour> ... </RequestColour> 

The answer looks like this:

 <ResponseColourOutput> ... </ResponseColourOutput> 

What libraries should I use in Python to send these xml requests and get responses?

+4
source share
4 answers

You can use the urllib2 module that comes with Python to query the url that can use it.

There is a decent tutorial on the Python website on how to use this module to extract Internet resources. The next step is to learn how to generate / consume XML.

The relevant SO answers for these steps are:

+3
source

I posted a small example of a simple XML request and response in Python here:

http://it.toolbox.com/blogs/lim/request-get-reply-and-display-xml-in-python-beauty-of-simplicity-49791

Please, not that my example sends arbitrary XML and receives valid XML, but it informs you of an error because the contents of the request were not recognized.

You can use your own URL and XML, or configure not to send an XML request and just parse the response to the provided XML.

I would also suggest exploring the eBays example for the x.Commerce XML API, which can be accessed from Python.

Hope this helps.

+1
source

If the XML version being processed is simple, try looking at the built-in API, xml.etree.ElementTree .

0
source

I found this site that will be invaluable for all my python training.

In your particular case, try here .

0
source

Source: https://habr.com/ru/post/1335122/


All Articles