mvantellingen / python-zeep

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

TypeError with choice element #348

Closed xWo0d closed 7 years ago

xWo0d commented 7 years ago
  1. zeep 1.0 python 3.5.2

  2. http://109.195.183.171:2121/socportal/smev/TravelPrivilege256.ashx?wsdl

  3. Performing -mzeep i look this: TravelPrivilege(Message: ns0:MessageType, MessageData: {AppData: {TravelPrivilege: , _attr_1: {}}}, _soapheaders={SmevHeader: ns0:HeaderType})

I have trouble with passing Message: From mzeep ns0:MessageType(Sender: ns0:orgExternalType, Recipient: ns0:orgExternalType, Originator: ns0:orgExternalType, ({ServiceName: xsd:string} | {Service: ns0:ServiceType}), TypeCode: ns0:TypeCodeType, Status: ns0:StatusType, Date: xsd:dateTime, ExchangeType: xsd:string, RequestIdRef: ns0:idType, OriginRequestIdRef: ns0:idType, ServiceCode: xsd:string, CaseNumber: xsd:string, SubMessages: ns0:SubMessagesType, TestMsg: xsd:string, OKTMO: xsd:string)

({ServiceName: xsd:string} | {Service: ns0:ServiceType}) - choice element, which has not qname field.

So, i try to get response using this code:

def wsdlzeep():
    wsdl = 'http://109.195.183.171:2121/socportal/smev/TravelPrivilege256.ashx?wsdl'
    client = Client(wsdl=wsdl)
    client.bind('TravelPrivilegeSoap', 'TravelPrivilege')

    msgtype = client.get_type('ns0:MessageType')
    msgdtype = client.get_type('ns0:MessageDataType')
    appdatatype = client.get_type('ns0:AppDataType')
    servicetype = client.get_type('ns0:ServiceType')
    msg = msgtype(Sender={'Code': '926701721', 'Name': '123'},
                  Recipient={'Code': '926701721', 'Name': '123'},
                  Originator={'Code': '926701721', 'Name': '123'},
                  Service=servicetype({'Mnemonic': '123', 'Version': '1.00'}),
                  ServiceName='TravelPrivilegeSoap',
                  TypeCode='GSRV',
                  Status='REQUEST',
                  Date=datetime.datetime(2016, 9, 23, 9, 30),
                  ExchangeType='2',
                  TestMsg='Test',
                  OKTMO='70000000')

    value = xsd.AnyObject(xsd.String(), 'Citizen')
    appdata = appdatatype(_value_1=value, _attr_1={'FamilyName': 'abc', 'FirstName': '123',
                                                    'Patronymic': '324',
                                                   'BirthDate': '1990-01-01', 'RayonID': '0', 'CategoryLgot': 'a',
                                                   'TravelDate': '1990-01-01'})
     msgd = msgdtype(AppData=appdata)
     return print(client.service.TravelPrivilege(Message=msg, MessageData=appdata))

That request return:

Traceback (most recent call last):
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/xwood/PycharmProjects/API-huyapi/app/views.py", line 829, in wsdlzeep
    return print(client.service.TravelPrivilege(Message=msg, MessageData=appdata))
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/client.py", line 41, in __call__
    self._op_name, args, kwargs)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 115, in send
    return self.process_reply(client, operation_obj, response)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 167, in process_reply
    result = operation.process_reply(doc)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 335, in process_reply
    return self.output.deserialize(envelope)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/wsdl/messages/soap.py", line 75, in deserialize
    body_result = self._deserialize_body(body)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/wsdl/messages/soap.py", line 376, in _deserialize_body
    result = self.body.parse(xmlelement, self.wsdl.types)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/elements/element.py", line 98, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/types/complex.py", line 140, in parse_xmlelement
    elements, schema, name, context=context)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/elements/indicators.py", line 470, in parse_xmlelements
    xmlelements, schema, name, context=context)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/elements/element.py", line 131, in parse_xmlelements
    xmlelement, schema, allow_none=True, context=context)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/elements/element.py", line 98, in parse
    xmlelement, schema, allow_none=allow_none, context=context)
  File "/home/xwood/PycharmProjects/API-huyapi/.env/lib/python3.5/site-packages/zeep/xsd/types/complex.py", line 144, in parse_xmlelement
    raise XMLParseError(exc.message)
zeep.exceptions.XMLParseError: Unexpected element '{http://smev.gosuslugi.ru/rev120315}TypeCode', expected '{http://smev.gosuslugi.ru/rev120315}Service'
192.168.88.48 - - [16/Feb/2017 17:36:15] "POST /wsdlzeep HTTP/1.1" 503 -
INFO:werkzeug:192.168.88.48 - - [16/Feb/2017 17:36:15] "POST /wsdlzeep HTTP/1.1" 503 -

How do I transfer the choice item correctly? I tried different options.

P.S. Sorry for my english

vstoykov commented 7 years ago

You could try this:

client.service.TravelPrivilege({'Message': msg, 'MessageData': appdata})
xWo0d commented 7 years ago

It does not work. The main problem with Choice element({ServiceName: xsd:string} | {Service: ns0:ServiceType}), which has not qname parameter.

mvantellingen commented 7 years ago

Hi,

First of all don't worry about your english :-)

It would be easier for me though if there is an example script as explained in the documentation (see http://docs.python-zeep.org/en/master/reporting_bugs.html).

I realise this will result in extra work on your side, but it would make it easier for me to look at it :-)