Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse the output of subprocess.call() from Python

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)
like image 716
Ishu Gupta Avatar asked Feb 24 '15 16:02

Ishu Gupta


1 Answers

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.

like image 178
Padraic Cunningham Avatar answered Sep 24 '22 01:09

Padraic Cunningham