Passing parameters to SOAP Zeep client

989 views
Skip to first unread message

giuseppe ricci

unread,
Nov 28, 2017, 4:20:06 AM11/28/17
to Django users
I'm using Zeep library to query a SOAP webservice wrote in Java.
My piece of the wsdl file is:

<soapenv:Header/>
<soapenv:Body>
  <pag:creaCarrello>
     <GestioneCarrelliRequest>
        <utenteApplicativo>XXXX</utenteApplicativo>
        <carrelloDto>
           <idCarrelloSorgente>11223344</idCarrelloSorgente>
           <itemCarrelloDtoList>
              <causale>prova</causale>
              <codiceEnte>CCIAA_MI</codiceEnte>
              <importo>2</importo>
              <importoImposta>1</importoImposta>
              <importoTotale>3</importoTotale>
              <importoUnitario>2</importoUnitario>
              <quantitaItem>1</quantitaItem>
              <tipoContabilizzazione>TA</tipoContabilizzazione>
           </itemCarrelloDtoList>
        </carrelloDto>
     </GestioneCarrelliRequest>
  </pag:creaCarrello>

and I create a SOAP client in this manner:

def soapclient(request):

     session = Session()
     session.auth = HTTPBasicAuth('user', 'password', transport=Transport(session=session))
     client = Client('my_url_of_wsdl_file.wsdl')

     utenteApplicativo='XXXX'     
     idCarrelloSorgente=11223344
     itemCarrelloDtoList=('prova', 'Datatest', 2, 1, 3, 2, 1, 'TA')
     carrelloDto=(idCarrelloSorgente, itemCarrelloDtoList)
     var=(utenteApplicativo, carrelloDto)
     call=client.service.creaCarrello(var)
     var=(utenteApplicativo, carrelloDto) 

     print('variabile del client: ', var)

     call1=client.service.creaCarrello(var)

     print(call1)
 
but I receive the error: 

ValidationError at /soapclient/
Missing element utenteApplicativo (creaCarrello.GestioneCarrelliRequest)
The problem it seems the manner of passing the parameters. With this other manner:

call=client.service.creaCarrello(XXXX', {11223344, {'causale':'prova', 'codiceEnte':'CCIAA_MI', \
'importo':2, 'importoImposta':1, 'importoTotale':3, 'importoUnitario':2, 'quantitaItem':1, 'tipoContabilizzazione':'TA'}, },)

I receive the error: unhashable type: 'dict'.

Can you help me to understand what is the correct manner to pass these parameters to the zeep client? There are a set of parameters inside another set..Is it supported by zeep?
Thanks.

James Schneider

unread,
Nov 28, 2017, 4:49:10 AM11/28/17
to django...@googlegroups.com


On Nov 28, 2017 1:20 AM, "giuseppe ricci" <peppep...@gmail.com> wrote:
I'm using Zeep library to query a SOAP webservice wrote in Java.
My piece of the wsdl file is:

This is the Django users mailing list, so we probably won't be of much help. You should investigate the support forums for Zeep. 

I piloted a small program using it a year or so ago, but I don't have much experience with it as the project went south for other reasons. Neat library to handle the awfulness that is SOAP.


ValidationError at /soapclient/
Missing element utenteApplicativo (creaCarrello.GestioneCarrelliRequest)
The problem it seems the manner of passing the parameters. With this other manner:

call=client.service.creaCarrello(XXXX', {11223344, {'causale':'prova', 'codiceEnte':'CCIAA_MI', \
'importo':2, 'importoImposta':1, 'importoTotale':3, 'importoUnitario':2, 'quantitaItem':1, 'tipoContabilizzazione':'TA'}, },)

I receive the error: unhashable type: 'dict'.

Can you help me to understand what is the correct manner to pass these parameters to the zeep client? There are a set of parameters inside another set..Is it supported by zeep?
Thanks.

If memory serves, yes, you can nest parameters and values in a request, pretty sure I've done it. However, your code is not using nested dictionaries. It appears you are missing a dict key (and possibly a ' unless that's from sanitizing the code). The way your code stands, the second parameter is a Python set, and the second element of that set is a dict, which can't be hashed. Hashing is required for sets, but not for dicts. 

Most likely you meant for the set to be a dict, but forgot to include the keys. I think Zeep exclusively used dicts and lists in their method calls to ease XML serialization, unless something has changed recently.

But again, you'll find better help on the Zeep forums.

-James

giuseppe ricci

unread,
Nov 28, 2017, 7:22:50 AM11/28/17
to Django users
Thanks James for your precious suggestions. 
Unfortunatly Zeep haven't a support forum, so I tryed on the django-users group.
According your suggestions I try with:


var=({'utenteApplicativo': 'YZSMOPMO'}, {'carrelloDto':{'idCarrelloSorgente': '99999999994'}, 'itemCarrelloDtoList':{'causale': 'prova', 'codiceEnte':'CCIAA_MI', \
'importo':2, 'importoImposta':1, 'importoTotale':3, 'importoUnitario':2, 'quantitaItem':1, 'tipoContabilizzazione':'TA'}})
print('variabile: ', var)
print(type(var))

call=client.service.creaCarrello(var)
in this manner I have a list variable: var. But I receive the error:

Missing element utenteApplicativo (creaCarrello.GestioneCarrelliRequest)

It is not the correct manner.
Any help are welcome.
Thanks.
Reply all
Reply to author
Forward
0 new messages