从Python代码调用外部Web服务

时间:2015-02-23 20:24:04

标签: python web-services curl

目前我在Unix中从命令行调用外部Web服务:

curl --cert externalcertificate.cer --data @SampleRequest.xml -v https://world-service-dev.intra.a.com:4414/worldservice/CLIC/CaseManagementService/V1

我需要在我的python代码中集成这个调用。然后我将围绕它进行重试逻辑和响应验证,这个调用的最佳方式是什么?由于它是单向SSL,我还需要确保我的Web服务调用也是指我服务器上保存的外部服务器证书。

我无法使用Python的请求模块,因为它没有安装在服务器上,我尝试使用urllib2但面临与ssl相关的多个问题,因为它是一个https调用。  现在我正在尝试调用子流程模块: subprocess.call(['curl', '-k', '-H' , 'content-type: application/soap+xml' ,'-d', etree.tostring(tree), '-v' ,'"https://world-service-dev.intra.aexp.com:4414/worldservice/CLIC/CaseManagementService/V1"'])

但收到错误消息:

* Protocol "https not supported or disabled in libcurl curl: (1) Protocol "https not supported or disabled in libcurl

2 个答案:

答案 0 :(得分:1)

我会使用Requests来调用该网络服务。

答案 1 :(得分:0)

我的网址前面有一个额外的双引号导致此问题发生,这是正确的语法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'])

相关问题