【问题标题】:Python zeep - XML tag missing type declaration for string typePython zeep - XML 标记缺少字符串类型的类型声明
【发布时间】:2018-10-16 10:30:10
【问题描述】:

使用zeep时,如下代码:

string_type = client.get_type("xsd:string")
string_expression = string_type("my string value")

结果如下:

<ns1:Value>my string value</ns1:Value>

SOAP 服务器上的序列化程序所期望的实际上是这样的:

<ns1:Value xsi:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">my string value</ns1:Value>

这种差异导致 SOAP 服务器抛出异常:

zeep.exceptions.Fault:格式化程序在尝试时抛出异常 反序列化消息:尝试 反序列化参数http://Services.IPWS/。这 InnerException 消息是“来自命名空间的元素值” http://schemas.datacontract.org/ 不能将子内容反序列化为对象。请用 XmlNode[] 来反序列化这种 XML 模式。请参见 InnerException 了解更多详情。

如何让 zeep 保留 XML 标记中的类型声明?

【问题讨论】:

    标签: python api soap zeep


    【解决方案1】:

    我找到了一种让 zeep 生成以下标记的方法,这是 SOAP 服务器所期望的:

    value = zeep.xsd.AnyObject(zeep.xsd.String(), "my string value")
    

    这会导致:

    <ns1:Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">my string value</ns1:Value>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      相关资源
      最近更新 更多