【问题标题】:Passing parameters to zeep client将参数传递给zeep客户端
【发布时间】:2017-11-24 16:09:46
【问题描述】:

我有这个 wsdl 文件:

<soapenv:Header/>
<soapenv:Body>
  <pag:creaCarrello>
     <GestioneCarrelliRequest>
        <utenteApplicativo>YZSMOPMO</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>

这是一个用 Java 编写的 SOAP 服务。我需要查询这个服务,我正在使用 python Zeep 库:

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)

但我从 Django 收到错误:

ValidationError at /soapclient/
Missing element utenteApplicativo (creaCarrello.GestioneCarrelliRequest)

参数传递方式错误?

【问题讨论】:

  • 你能把整个 zeep 的实现放上去吗
  • 更新了 zeep 客户端的所有视图。

标签: python django soap wsdl zeep


【解决方案1】:

用这个例子:

def soapclient(request):

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

     call=client.service.creaCarrello(
      utenteApplicativo='YZSMOPMO',
      carrelloDto= {
       idCarrelloSorgente=11223344,
       itemCarrelloDtoList= {
        causale='prova'
        codiceEnte='CCIAA_MI',
        importo=2,
        importoImposta=1,
        importoTotale=3,
        importoUnitario=2,
        quantitaItem=1,
        tipoContabilizzazione='TA'
       }
      }
     )

【讨论】:

  • idCarrelloSorgente 行上的语法无效..似乎正确..有什么想法吗?
【解决方案2】:

错误是。

invalid syntax (views.py, line 193) 

其中 193 是定义 idCarrelloSorgente=11223344 的行。 以这种方式传递:

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

我收到错误:

unhashable type: 'dict'

这些似乎是向客户端传递参数的错误方式。

【讨论】:

  • 您应该使用这种方法指定您的参数:client.service.SERVICE_NAME(parameter_name='value')
猜你喜欢
  • 2019-03-16
  • 2023-03-29
  • 2016-06-16
  • 1970-01-01
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
相关资源
最近更新 更多