从 Python 解析 subprocess.call() 的输出

Parse the output of subprocess.call() from Python

我正在从我的 Python 代码调用网络服务:

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'])

服务 returns 一个 soap 消息,我如何解析 soap 消息并确定它是失败还是成功?

我尝试使用以下方法,但得到的结果是错误的:

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)

不要 PIPE 只调用 check_output 传递参数列表并删除 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"])

如果您获得非零退出代码,您将获得 CalledProcessError