PySimpleSoap:如何将 complexType 作为函数参数传递 [英] PySimpleSoap: How to pass a complexType as a function parameter

查看:20
本文介绍了PySimpleSoap:如何将 complexType 作为函数参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 wsdl 文件,其中包含一个名为 ImportTransportDocument 的函数.该函数接受 3 个参数、一个会话 ID、选项和一个文档.

I have a wsdl file with a function called ImportTransportDocument. The function takes 3 parameters, a session ID, options and a document.

在没有选项的情况下调用函数效果很好,但是当我尝试提交选项参数时,它会引发异常.

Calling the function without options works well, but when I try to submit the options parameter it throws an exception.

options 参数是一个复杂类型.

The options parameter is a complex type.

我必须以哪种格式提交复杂类型?我尝试了一个普通的字符串和一个字典,但没有成功.

In which format do I have to submit the complex type? I tried a plain string and a dictionary without success.

wsdl 包含以下信息:

The wsdl contains the following information:

   <element name="ImportTransportDocument">
   <complexType>
    <sequence>
     <element name="sessionid" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
     <element name="options" type="eakte2:transportoption" minOccurs="0" maxOccurs="1" nillable="true"/>
     <element name="base64data" type="xsd:base64Binary" minOccurs="0" maxOccurs="1" nillable="true"/>
    </sequence>
   </complexType>
  </element>
    ....
<complexType name="transportoption">
   <sequence>
     <element name="distribution" type="xsd:string" minOccurs="1" maxOccurs="1"/>
     <element name="dekadenmeldung" type="xsd:string" minOccurs="1" maxOccurs="1"/>
     <element name="storno" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
   </sequence>
  </complexType>

调用 .help() 方法显示

Calling the .help() method shows

ImportTransportDocument(sessionid=, options={u'distribution': , u'dekadenmeldung': , u'storno': }, base64data=)-> {u'message': , u'message2': }:

ImportTransportDocument(sessionid=, options={u'distribution': , u'dekadenmeldung': , u'storno': }, base64data=) -> {u'message': , u'message2': }:

    opt = {'distribution': '', 'dekadenmeldung': 'true', 'storno': 'true'}
    self.result = self.client.ImportTransportDocument(self.session_id, opt, base64.encodestring(doc))

给出以下异常:

 File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 181, in <lambda>
return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)
 File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 346, in wsdl_call
return self.wsdl_call_with_args(method, args, kwargs)
 File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 367, in wsdl_call_with_args
method, params = self.wsdl_call_get_params(method, input, args, kwargs)
 File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 390, in wsdl_call_get_params
raise KeyError('Unhandled key %s. use client.help(method)' % key)
KeyError: u'Unhandled key options. use client.help(method)'

有什么提示吗?

非常感谢,哈拉尔

推荐答案

我自己找到了解决方案.如果字典作为参数传递,PySimpleSOAP 需要命名参数:

I found the solution myself. If a dictionary is passed as a parameter, PySimpleSOAP expects named parameters:

self.result = self.client.ImportTransportDocument(sessionid=self.session_id, options=opt, base64data=base64.encodestring(doc))

干杯,哈拉尔

这篇关于PySimpleSoap:如何将 complexType 作为函数参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆