Zeep setting defined valuesas 'NotSet'
Hi, I am experience the following behavior:
def getDeviceDetail(client=None, auth=None, dbid=None): from lxml import etree component = dict({'type':'device', 'dbid':dbid}) print(component) node = client.create_message(client.service, 'detailQuery', auth=auth, component=component) print(etree.tostring(node, encoding="unicode", pretty_print=True)) r = client.service.detailQuery(auth=auth, component=component)
getDeviceDetail(client=client, auth=creds, dbid=1234)
The output is as follows:
print(component): {'type': 'device', 'dbid': 1234}
print(etree.tostring(node, encoding="unicode", pretty_print=True)):
(Skipping the rest of the output) <component type="NotSet" dbid="NotSet"/>
zeep version is 3.4.0 Any idea?
I'm having this same issue. Did you ever find out anything on this?
<component type="NotSet" dbid="NotSet"/>
I did test this morning, and this works correctly using suds-community.
yes you need to override the transport.py
I have overridden the method like
`
def post_xml(self, address, envelope, headers):
"""Post the envelope xml element to the given address with the headers.
This method is intended to be overriden if you want to customize the
serialization of the xml element. By default the body is formatted
and encoded as utf-8. See ``zeep.wsdl.utils.etree_to_string``.
"""
message = etree_to_string(envelope)
if 'Radius="NotSet"' in message.decode('utf-8'):
message = message.decode('utf-8').replace('Radius="NotSet"', 'Radius="10.00"')
message = message.encode('utf-8')
return self.post(address, message, headers)
`
It appears that Zeep is not populating the values of the automatically converted object from the dictionary we are passing it.
Using get_type:
component_type = client.get_type('{http://www.nates.fr/API/1.0}COMPONENT_TYPE')
component = component_type(type=tenant['type'], dbid=int(tenant['dbid']))
Or factory:
factory = client.type_factory('ns0')
component = factory.COMPONENT_TYPE(type=tenant['type'], dbid=int(tenant['dbid']))
Generates this XML:
<component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" type="TENANT" dbid="XXX" xsi:type="ns0:COMPONENT_TYPE"/>
Which results in the following error coming back from the API:
org.xml.sax.SAXParseException; cvc-elt.4.3: Type 'ns0:COMPONENT_TYPE' is not validly derived from the type definition, 'null', of element 'component'.
But passing in the dictionary instead, generates the correctly formatted XML that the API is expecting, it's just not populating the values as we would expect:
<component type="NotSet" dbid="NotSet"/>
@ciscomonkey I've got similar issues, only that your solution doesn't work for me because my object is used as attribute, not as child tag...
hi @ciscomonkey. Did you figure out a solution for this or just used suds-community instead.
Not sure if I get your comment above where you mentioned:
But passing in the dictionary instead, generates the correctly formatted XML that the API is expecting, it's just not populating the values as we would expect:
What do you mean? Can you provide an example?
Thanks
@elmorek I just went with suds-community for this project.
I've been experiencing the same problem
When passing a dict to a Operation (eg {"locale": "EN", "aNumber": "1234"}), it results in a Request with "NotSet":
<Request locale="NotSet" aNumber="1234" />
Here's en excerpt of the WSDL
<xs:complexType name="getOrderDetails">
<xs:sequence>
<xs:element minOccurs="0" name="Request" type="tns:orderStateDetailReq"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="orderStateDetailReq">
<xs:complexContent>
<xs:extension base="tns:frontendServiceParam">
<xs:sequence/>
<xs:attribute name="aNumber" type="xs:string"/>
<xs:attribute name="pNumber" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="frontendServiceParam">
<xs:complexContent>
<xs:extension base="tns:defaultServiceParam">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="defaultServiceParam">
<xs:complexContent>
<xs:extension base="tns:localeHolder">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="localeHolder">
<xs:sequence/>
<xs:attribute name="locale" type="tns:localeType" use="required"/>
</xs:complexType>
<xs:simpleType name="localeType">
<xs:restriction base="xs:string">
<xs:enumeration value="DE"/>
<xs:enumeration value="EN"/>
</xs:restriction>
</xs:simpleType>
@powo Did you find a solution?