【发布时间】:2015-04-26 09:56:51
【问题描述】:
我正在调用我的 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'])
服务返回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)
【问题讨论】:
-
再试一次
check_output,但要确保第一个参数是一个列表,就像call一样。只提供一个字符串可能会导致异常结果。 -
您不需要
curl在 Python 中发出 http post 请求,例如out = urllib2.urlopen(url, data, headers={'content-type': '...'}).read()。有soap clients in Python,例如suds,但我会尝试发送/接收裸xml(以解决soap-stacks之间的各种不兼容性)——你可以使用xml.etree.cElementTree来解析它。
标签: python python-2.7 subprocess