Python-zeep: Zeep setting defined valuesas 'NotSet'

Created on 31 Jul 2019  路  7Comments  路  Source: mvantellingen/python-zeep

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?

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nihankarslioglu picture nihankarslioglu  路  4Comments

allan-simon picture allan-simon  路  4Comments

olivierverville picture olivierverville  路  3Comments

vadivelkindhealth picture vadivelkindhealth  路  3Comments

YAmikep picture YAmikep  路  3Comments