我正在尝试使用Zeep在序列中选择,但我无法使其工作。
这是我的代码:
#create trade ref element
tradeReference_element = client.get_element('ns4:tradeReference')
trade_ref_object = xsd.AnyObject(tradeReference_element, tradeReference_element(tradeId="NKY 12/08/17 C21000"))
#create export element
export_element = client.get_element('ns32:export')
export_element_object = xsd.AnyObject(export_element, export_element(_value_1={'tradeReference' : trade_ref_object}))
#use exportEntities service
client.service.exportEntities(export=export_element_object)
我收到以下错误:
client.service.exportEntities(export=export_element_object)
Traceback (most recent call last):
File "<ipython-input-14-3cee211bc26a>", line 1, in <module>
client.service.exportEntities(export=export_element_object)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\client.py", line 41, in __call__
self._op_name, args, kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\wsdl\bindings\soap.py", line 110, in send
options=options)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\wsdl\bindings\soap.py", line 68, in _create
serialized = operation_obj.create(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\wsdl\definitions.py", line 197, in create
return self.input.serialize(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\wsdl\messages\soap.py", line 63, in serialize
body_value = self.body(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\elements\element.py", line 48, in __call__
instance = self.type(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\types\complex.py", line 42, in __call__
return self._value_class(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\valueobjects.py", line 89, in __init__
items = _process_signature(self._xsd_type, args, kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\valueobjects.py", line 199, in _process_signature
values = element.parse_kwargs(kwargs, None, available_kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\elements\indicators.py", line 204, in parse_kwargs
sub_result = element.parse_kwargs(kwargs, elm_name, available_kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\elements\element.py", line 118, in parse_kwargs
kwargs, name or self.attr_name, available_kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\types\complex.py", line 278, in parse_kwargs
value = self._create_object(value, name)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\types\complex.py", line 303, in _create_object
return self(value)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\types\complex.py", line 42, in __call__
return self._value_class(*args, **kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\valueobjects.py", line 89, in __init__
items = _process_signature(self._xsd_type, args, kwargs)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\valueobjects.py", line 176, in _process_signature
values, args, index = element.parse_args(args, index)
File "C:\ProgramData\Anaconda2\lib\site-packages\zeep\xsd\elements\indicators.py", line 130, in parse_args
raise TypeError("Choice elements only work with keyword arguments")
TypeError: Choice elements only work with keyword arguments
所以似乎问题是&#34;选择元素仅适用于关键字参数&#34;
我的导出element_object如下:
<AnyObject(type=<Element(name=u'export', type=<zeep.xsd.dynamic_types.ExportMessage object at 0x0D966490>)>, value={
'header': None,
'validation': [],
'_value_1': [
{
'tradeReference': <AnyObject(type=<Element(name=u'tradeReference', type=<zeep.xsd.dynamic_types.TradeReference object at 0x0D394C30>)>, value={
'tradeId': {
'_value_1': 'NKY 12/08/17 C21000',
'tradeIdScheme': None
},
'href': None,
'ID': None
}
}
],
'version': None,
'batchType': 'NoSession',
'followDependencies': 'false',
'exportReferencesOnly': 'false'
})>
我认为问题是&#34; _value_1&#34;但它是由Zeep和关键字&#39; tradeReference&#39;创建的。在那里。
有谁能请我指出我做错了什么?
导出元素:
<xsd:complexType name="ExportMessage">
<xsd:complexContent>
<xsd:extension base="fpml:Message">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="party:partyReference">...</xsd:element>
<xsd:element ref="trade:tradeReference">...</xsd:element>
<xsd:element ref="valuation:market">...</xsd:element>
</xsd:choice>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="export" type="tns:ExportMessage" substitutionGroup="tns:message"/>
tradeReference元素:
<xsd:complexType name="TradeReference">
<xsd:sequence>
<xsd:element name="tradeId" type="tns:TradeId" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="href" use="optional"/>
<xsd:attribute name="ID" type="xsd:ID" use="optional"/>
</xsd:complexType>
<xsd:element name="tradeReference" type="tns:TradeReference"/>
和服务:
exportEntities(export: ns32:ExportMessage) -> message: ns30:Message, error: ns34:Error