如何在 Python 中为 WSDL 创建 arrayType(使用 suds)?

发布于 2024-07-27 05:33:59 字数 1449 浏览 9 评论 0原文

环境:

  • Python v2.6.2
  • suds v0.3.7

我使用的 WSDL(服务器)具有以下模式子部分(我尝试使用纯文本清楚地写出它) -


[ sub-section #1 ]

searchRequest: (searchRequest){
    userIdentification = (userIdentification){
        username = ""
        password = ""
        }
    itineraryArr = (itineraryArray){
        _arrayType = ""
        _offset = ""
        _id = ""
        _href = ""
        _arrayType = ""
        }
   ...
   ...

[ sub-section #2 ]

itinerary: (itinerary){
    departurePoint = (locationPoint){
        locationId = None
        radius = None
        }
    arrivalPoint = (locationPoint){
        locationId = None
        radius = None
        }
   ...
   ...

'userIdentification' 没有问题(这是一个“ simple”类型)

但是,'itineraryArr'是一个'itinerary'数组,我不知道如何使用python创建XML数组。

例如,我尝试了几种组合,

itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray = [itinerary0]
searchRequest.itineraryArr = itineraryArray

但是我所有的尝试都导致了相同的服务器错误 -

    Server raised fault: 'Cannot use object of type itinerary as array'
    (Fault){
       faultcode = "SOAP-ENV:Server"
       faultstring = "Cannot use object of type itinerary as array"
     }

Environment:

  • Python v2.6.2
  • suds v0.3.7

The WSDL (server) I work with, have the following schema sub-sections (I tried to write it clearly using plain text) -


[ sub-section #1 ]

searchRequest: (searchRequest){
    userIdentification = (userIdentification){
        username = ""
        password = ""
        }
    itineraryArr = (itineraryArray){
        _arrayType = ""
        _offset = ""
        _id = ""
        _href = ""
        _arrayType = ""
        }
   ...
   ...

[ sub-section #2 ]

itinerary: (itinerary){
    departurePoint = (locationPoint){
        locationId = None
        radius = None
        }
    arrivalPoint = (locationPoint){
        locationId = None
        radius = None
        }
   ...
   ...

There is no problem with 'userIdentification' (which is a "simple" type)

But, 'itineraryArr' is an array of 'itinerary', and I don't know how to use python to create XML array.

I tried few combinations, for example

itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray = [itinerary0]
searchRequest.itineraryArr = itineraryArray

But all my trials resulted with the same server error -

    Server raised fault: 'Cannot use object of type itinerary as array'
    (Fault){
       faultcode = "SOAP-ENV:Server"
       faultstring = "Cannot use object of type itinerary as array"
     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深白境迁sunset 2024-08-03 05:33:59

我处于同样的情况,使用 RPC/编码样式 WS 和包含肥皂数组的方法。 打印请求(其中 request = client.factory.create('Request'))给出:

(Request){
  requestid = None
  option = 
    (ArrayOfOption){
     _arrayType = ""
     _offset = ""
     _id = ""
     _href = ""
     _arrayType = ""
  }
 }

Jacques 给出的解决方案 (1request.option.append(option1)1) 不起作用,因为它结束了并显示错误消息ArrayOfOption实例没有属性append

mcauth 给出的解决方案如下所示:

array = client.factory.create('ArrayOfOption')
array.item = [option1,  option2,  option3,  option4,  option5,  option6]
request.option=array

它工作得如此,因为生成的 SOAP 消息没有显示 arrayType 属性:

<option xsi:type="ns3:ArrayOfOption">

我发现的最佳解决方案也是最简单的:

request.option = [option1,  option2,  option3,  option4,  option5,  option6]

良好的 SOAP 消息结束:

<option xsi:type="ns0:ArrayOfOption" ns3:arrayType="ns0:Option[6]">

它以 服务器端 WS 所期望的。

I'm in the same case, with a RPC/encoded style WS and a method that contains a soap array. a print request (where request = client.factory.create('Request')) gives:

(Request){
  requestid = None
  option = 
    (ArrayOfOption){
     _arrayType = ""
     _offset = ""
     _id = ""
     _href = ""
     _arrayType = ""
  }
 }

The solution given by Jacques (1request.option.append(option1)1) does not work, as it ends with an error message ArrayOfOption instance has no attribute append.

The solution given by mcauth looks like this:

array = client.factory.create('ArrayOfOption')
array.item = [option1,  option2,  option3,  option4,  option5,  option6]
request.option=array

It works so so, as the resulting SOAP message shows no arrayType attribute:

<option xsi:type="ns3:ArrayOfOption">

The best solution I found is also the simplest:

request.option = [option1,  option2,  option3,  option4,  option5,  option6]

It ends with a good SOAP message:

<option xsi:type="ns0:ArrayOfOption" ns3:arrayType="ns0:Option[6]">

as expected by the server side WS.

南城旧梦 2024-08-03 05:33:59

我相信您正在寻找的是:

itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
print itineraryArray
itineraryArray.itinerary.append(itinerary0)

我自己必须这样做;)帮助我找到它的是打印到控制台。 这可能会给你带来以下结果:

 (itineraryArray){
   itinerary[] = <empty>
 }

干杯,雅克

I believe what you are looking for is:

itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
print itineraryArray
itineraryArray.itinerary.append(itinerary0)

Just had to do this myself;) What helped me find it was printing to the console. That would have probably given you the following:

 (itineraryArray){
   itinerary[] = <empty>
 }

Cheers,Jacques

二智少女猫性小仙女 2024-08-03 05:33:59

对于这种类型的结构,我在数组对象上设置了一个名为“item”的属性,然后将列表成员附加到它。 类似于:

itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray.item = [itinerary0]

即使对于具有多个级别的复杂调用,它也能很好地解析和传递。

For this type of structure I set an attribute called 'item' on the array object and then append the list member to it. Something like:

itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray.item = [itinerary0]

Which parses and passes in fine, even for complex calls with multiple levels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文