python SOAP 添加 header

标签 python soap header soappy

我有以下 PHP 示例代码:

$client = new SoapClient("http://example.com/example.wsdl");

$h = Array();
array_push($h, new SoapHeader("http://example2.com/example2/", "h", "v"));
$client->__setSoapHeaders($h);

$s = $client->__soapCall('Op', $data);

我的问题:SoapHeader() 和 __setSoapHeaders() 部分的 SOAPpy 等效项是什么?

相关问题

最佳答案

这是一个使用 suds 的示例库(SOAPpy 的替代品)。它假定自定义 header 未在 wsdl 中定义。

from suds.client      import Client
from suds.sax.element import Element

client = Client("http://example.com/example.wsdl")

# <tns:h xmlns:tns="http://example2.com/example2/">v</tns:h>
tns = ("tns", "http://example2.com/example2/")
h = Element('h', ns=tns).setText('v')
client.set_options(soapheaders=h) 
#
s = client.service.Op(data)

关于 python SOAP 添加 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1856963/

相关文章:

Python递归置换程序讲解

ios - Objective-C - SOAP 请求返回 WSDL 作为响应而不是正确的响应

api - 尝试添加 X-Amz-Invocation-Type :Event to existing API Gateway POST method

php - 从 PHP 脚本返回 JSON

.net - 从代码访问 Silverlight DataGrid 列标题中的控件

python - Jinja2 模板的代码覆盖率

python - 计算前一行中大于当前行值的值

python - 为所有Flask路线添加前缀

java - Apache Camel RouteBuilder 配置方法

java - 如何在 Java 中将 SOAP 消息的字节数组转换为原始 XML