I was trying to create a ‘quick and dirty’ python SOAP client and was finding it difficult. The WSDL I was dealing with wasn’t a simple one, which, of course, made creating a client a bit more difficult. Add to the fact that I’m far from a python expert (have been tired of learning the ‘latest/greatest’ new toy), so finally started learning python reluctantly.
I found this post in StackOverflow that listed a number of python SOAP libraries and I started working through the examples. I finally settled on using SUDS. It’s not the most up-to-date library – the last development done on in was in 2010. But frankly, it’s the only one from which I could obtain results.
That being said, it wasn’t as straightforward as I would have liked. My first language is PERL; my second is Java. So maybe ‘thinking in python’ was not as easy for me. But still, I have found it a good language to work with, which is why I have been forcing myself to use it instead of PERL lately.
So, my code…..
There are groups of parameters in the WSDL I’m using, which required me to create dictionaries of dictionaries:
sort = dict(sortPolicyId='RELEVANCE',order='DESCENDING') criteria = dict(searchPhrase='test', sortPolicy=sort) params = dict(maximumResults=1000, searchTimeOut=24000) contextParams = dict(ContextualCriteria=criteria,SearchCriteriaParameters=params)
The next part, passing them, does come directly from the documentation:
results = client.service.contextualSearch(**contextParams)
Then the next hard part: I couldn’t figure out how to get the values out. What I finally found was an example for pysimplesoap that I could use: Pull the results from the results. That is:
resultList = results.results
At this point, I had something from which I could pull values:
for item in resultList: print item.catalogEntry.id
… which gave me the values I needed.