Python-zeep: zeep.exceptions.XMLParseError: Unexpected element

Created on 13 Jan 2017  路  5Comments  路  Source: mvantellingen/python-zeep

UPDATE - the response coming back from the wsdl is missing a column that is defined in the output schema - 'SellCurrency'. Zeep 0.14 handled this by including the column with a None value (certainly preferred behaviour from my point of view), whereas 0.24 raises an UnexpectedElementError. Is there a way to allow UnexpectedElements to simply fail silently and return a None as in previous versions?

I've got zeep working successfully in a project that is on Python 2.7 and the version of zeep is quite old, 0.14.

I'm rewriting the package in Python 3.5 as an api around a (not great) wsdl service, and I'm working using the latest zeep, 0.24. I've successfully replicated one function of the wsdl, moving onto a second function I encountered the above exception when zeep is attempting to parse the XML string. Aside from separate RequestIDs and timestamps (specific to this wsdl), the responses are identical between both versions of my api for this function call. However, the Python 3.5/Zeep 0.24 raises this exception. The only difference is obviously the response in 2.7 is 'the_reponse' vs 3.5 b'the_response'...

I'm linking to a gist which contains the string in it's entirety:
https://gist.github.com/jacksonwoody/6f8079fd2a8f29db1beac4ebac015747

The working 2.7/0.14 combination representation of the same data coming back successfully:
https://gist.github.com/jacksonwoody/7f4c2a8de271c30e7fcc6ca2bd69874d

The wsdl has the user/pw contained in the url, but subset of the wsdl which defines the function and response I'm using:
https://gist.github.com/jacksonwoody/8cbbfbbadb803b0b914de4b0d5e8d458

Actual Exception raised and traceback:

Traceback (most recent call last):
  File "H:\workspace\python\pyress\pyress\connection\request_processing.py", line 61, in send_request
    result = func(input.input)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\client.py", line 41, in __call__
    self._op_name, args, kwargs)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\wsdl\bindings\soap.py", line 113, in send
    return self.process_reply(client, operation_obj, response)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\wsdl\bindings\soap.py", line 151, in process_reply
    return operation.process_reply(doc)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\wsdl\bindings\soap.py", line 313, in process_reply
    return self.output.deserialize(envelope)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\wsdl\messages\soap.py", line 75, in deserialize
    body_result = self._deserialize_body(body)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\wsdl\messages\soap.py", line 363, in _deserialize_body
    result = self.body.parse(xmlelement, self.wsdl.types)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 275, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\types.py", line 310, in parse_xmlelement
    elements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\indicators.py", line 464, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 308, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 275, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\types.py", line 310, in parse_xmlelement
    elements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\indicators.py", line 464, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 308, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 275, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\types.py", line 310, in parse_xmlelement
    elements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\indicators.py", line 464, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 308, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 275, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\types.py", line 310, in parse_xmlelement
    elements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\indicators.py", line 464, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 308, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\elements.py", line 275, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "H:\virtualenvs\pyress\lib\site-packages\zeep\xsd\types.py", line 314, in parse_xmlelement
    raise XMLParseError(exc.message)
zeep.exceptions.XMLParseError: Unexpected element '{http://webservices.iress.com.au/v4/}ExercisePrice', expected '{http://webservices.iress.com.au/v4/}SellCurrency'

Thanks, amazing library!!

requiremore-info

Most helpful comment

This should now work with the strict mode setting, see http://docs.python-zeep.org/en/master/client.html#strict-mode

So use Client(wsdl, strict=False)

All 5 comments

Hi,

Thanks for the report. It is unfortunately missing an example script as explained in the documentation (see http://docs.python-zeep.org/en/master/reporting_bugs.html). This is also mentioned when you create the issue on github.

I realise this will result in extra work on your side, but I can really use the extra help.

Hi mate,

I've tried to setup the script, which has the response coming out of debugging:
https://gist.github.com/jacksonwoody/1c64093d2a7e85295badaebfcc94663b

However, I can't provide you the wsdl since it contains username and pw in it, so I've left the wsdl as 'WHAT_CAN_I_DO_HERE?'. I have included a subset of the schema relevant to this problem:
https://gist.github.com/jacksonwoody/8cbbfbbadb803b0b914de4b0d5e8d458

Is it possible for you to take a look with this slim amount of info? Apologies I can't provide the wsdl...

Hi mate,

Is there anything I can do to assist you looking into this?

Yeah, so the issue is that I really need the WSDL to look at this. Otherwise I need to recreate the wsdl with the info you required which requires a lot of trial and error.

If you can e-mail the WSDL then that might help me looking into this. If that is really not possible then I can offer commercial support to look into this issue.

This should now work with the strict mode setting, see http://docs.python-zeep.org/en/master/client.html#strict-mode

So use Client(wsdl, strict=False)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadivelkindhealth picture vadivelkindhealth  路  3Comments

olivierverville picture olivierverville  路  3Comments

pope1ni picture pope1ni  路  4Comments

alexfx picture alexfx  路  4Comments

grguthrie picture grguthrie  路  4Comments