【问题标题】:Call an external webservice from Python code从 Python 代码调用外部 Web 服务
【发布时间】:2015-02-23 20:24:03
【问题描述】:

目前我正在从 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 的 requests 模块,因为它没有安装在服务器上,我尝试使用 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

【问题讨论】:

    标签: python web-services curl


    【解决方案1】:

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

    【讨论】:

    • 我想我可以使用 r = requests.post(url, files=files) 但是我如何处理证书部分...我如何确保我在制作这个时也通过了服务器证书打电话。
    • 遗憾的是,我的 python 环境中没有安装 requests 库,并且由于它的 QA 环境,我也没有安装它的权限。我可以使用任何其他模块吗?
    • 看看这里的答案,特别是这个stackoverflow.com/a/2667545/3236133
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 2020-04-26
      • 1970-01-01
      • 2017-08-17
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多