使用Zeep时,带有序列的Choice得到了意外的关键字参数

2024-04-19 19:29:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用zeep库时遇到了以下问题。我的XSD具有以下XML结构:

<xs:complexType name="cofPaymentType">
    <xs:sequence>
        <xs:choice>
            <xs:sequence>
                <xs:element name="paymentInstrument" type="tns:paymentInstrument"/>
                <xs:element name="payment" type="tns:paymentType"/>
                <xs:element name="cvvCode" type="tns:cvvCodeType" minOccurs="0"/>
            </xs:sequence>
            <xs:sequence>
                <xs:element name="encryptedData" type="tns:encryptedDataType"/>
                <xs:element name="payment" type="tns:paymentType"/>
            </xs:sequence>
        </xs:choice>
        <xs:element name="tdsAuthResult" type="tns:tdsAuthResult" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

我正在传递以下数据:

data = {"encryptedData": {"field1": "foo", "field2":  "bar"}, "payment": payment}
response = client.service.payment(**data)

我收到的答复是:

{http://www.example.pl/integration/virtual/transaction/v1}cofPaymentType() got an unexpected keyword argument 'encryptedData'. Signature: `({paymentInstrument: {http://www.example.pl/integration/virtual/transaction/v1}paymentInstrument, payment: {http://www.example.pl/integration/virtual/transaction/v1}paymentType, cvvCode: {http://www.example.pl/integration/virtual/transaction/v1}cvvCodeType} | {encryptedData: {http://www.example.pl/integration/virtual/transaction/v1}encryptedDataType, payment: {http://www.example.pl/integration/virtual/transaction/v1}paymentType}), tdsAuthResult: {http://www.example.pl/integration/virtual/transaction/v1}tdsAuthResult`"}

但是字段encryptedData出现在第二个选项中。看起来只有第一选择被选中了。我说得对吗?我怎样才能得到第二选择?你知道吗

我还尝试使用factory=client.type\u工厂('ns0'),但结果是相同的。它看不到第二选择的元素。你知道吗

一般来说,zeep在将请求转换为XML结构方面存在问题。所以我甚至不能生成:https://python-zeep.readthedocs.io/en/master/client.html#creating-the-raw-xml-documents,因为上面描述了“got an unexpected keyword”。你知道吗


Tags: namehttpexamplewwwtypevirtualelementpayment