mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 585 forks source link

xs:choice minOccurs="0" items has to be included in the request #74

Closed dddtc2005 closed 8 years ago

dddtc2005 commented 8 years ago

I was trying to send a request to the server with the following code:

motype = 'EPSMultiSC@http://schemas.example.com/ma/HSS/'
moid = {'imsi': imsi}
moattr = {'CreateEPSMultiSC': {'imsi': imsi, 'msisdn': msisdn, 'epsProfileId': 'ExampleProfile'}}
response = soapclient.service.Create(motype, moid, moattr, _soapheader = sessionid)

The errors I got:

Traceback (most recent call last):
  File "test1.py", line 104, in epsmultisc_create
    mesg = soapclient.service._binding.create_message('Create', motype, moid, moattr, _soapheader=sessionid)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/wsdl/soap.py", line 56, in create_message
    serialized = operation.create(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/wsdl/definitions.py", line 245, in create
    return self.input.serialize(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/wsdl/messages.py", line 74, in serialize
    self.body.render(body, body_value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/elements.py", line 129, in render
    return self.type.render(node, value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/types.py", line 175, in render
    element.render(parent, sub_value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/elements.py", line 129, in render
    return self.type.render(node, value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/types.py", line 175, in render
    element.render(parent, sub_value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/elements.py", line 129, in render
    return self.type.render(node, value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/types.py", line 172, in render
    element.render(parent, name, value)
  File "/usr/lib/python2.7/site-packages/zeep-0.9.0.dev0-py2.7.egg/zeep/xsd/elements.py", line 221, in render
    choice_value = item.values.get(choice_element.name)
AttributeError: 'list' object has no attribute 'get'

have a few rounds of trial, and found that the items has to be included, otherwise it will fail. Therefore the following code works:

motype = 'EPSMultiSC@http://schemas.example.com/ma/HSS/'
moid = {'imsi': imsi}
moattr = {'CreateEPSMultiSC': {'imsi': imsi, 'msisdn': msisdn, 'epsProfileId': 'ExampleProfile', 'epsExtendedAccessRestriction': '32', 'commonMsisdn': msisdn}}
response = soapclient.service.Create(motype, moid, moattr, _soapheader = sessionid)

But in fact those items ("epsAccessRestriction" or "epsExtendedAccessRestriction", "epsCommonMsisdn" or "commonMsisdn") are optional, user should be able to choose to include them or not in the request.

WSDL & XSD: eps_wsdl_xsd.zip

dddtc2005 commented 8 years ago

Sorry for late feedback. Verified and passed. Thanks!