我从我的Python代码中调用Web服务:
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'])
该服务返回一条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)
答案 0 :(得分:5)
不要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
。