5

I am callign a webservice from my Python code :

response = subprocess.call(['curl', '-k', '-i', '-H' , 'content-type: application/soap+xml' ,'-d',  etree.tostring(tree), '-v' ,'https://world-service-dev.intra.aexp.com:4414/worldservice/CLIC/CaseManagementService/V1'])

The service returns a soap message , how do I parse the soap message and find out if it was a failure or success?

I tried to use the following but I am getting wrong results :

subprocess.check_output("curl -k --data "+etree.tostring(tree)+"@SampleRequest.xml -v  https://world-service-dev.intra.aexp.com:4414/worldservice/CLIC/CaseManagementService/V1",stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Ishu Gupta
  • 1,071
  • 1
  • 19
  • 43
  • 1
    Try `check_output` again, but make sure the first argument is a list, the way it was for `call`. Providing just a string can cause unusual results. – Kevin Feb 24 '15 at 16:51
  • Just use http://pycurl.sourceforge.net – Łukasz Rogalski Feb 24 '15 at 20:42
  • you don't need `curl` to make http post request in Python e.g., `out = urllib2.urlopen(url, data, headers={'content-type': '...'}).read()`. There are [soap clients in Python](http://stackoverflow.com/q/206154/4279) such as `suds` but I'd try to send/receive bare xml instead (to workaround various incompatibilities between soap-stacks) -- you could use `xml.etree.cElementTree` to parse it. – jfs Feb 24 '15 at 20:45

1 Answers1

5

Don't PIPE just call check_output passing a list of args and remove shell=True:

 out = subprocess.check_output(["curl", "-k","--data", etree.tostring(tree)+"@SampleRequest.xml", "-v",  "https://world-service-dev.intra.aexp.com:4414/worldservice/CLIC/CaseManagementService/V1"])

If you get a non-zero exit code you will get a CalledProcessError.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • thanks @Padraic , It works . How do I parse the soap message from the response that I got from this call ? Also assuming the call is successfull , is there a way I can parse the soap message that I will get from the response ? – Ishu Gupta Feb 24 '15 at 17:04
  • If the call does not return a 0 exit status you will get a `CalledProcessError`, if you want to store the output just store it in a variable `out = check_output...` – Padraic Cunningham Feb 24 '15 at 17:10