如何在 Python 中为 WSDL 创建 arrayType(使用 suds)?
环境:
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我处于同样的情况,使用 RPC/编码样式 WS 和包含肥皂数组的方法。 打印请求(其中
request = client.factory.create('Request')
)给出:Jacques 给出的解决方案 (1request.option.append(option1)1) 不起作用,因为它结束了并显示错误消息
ArrayOfOption实例没有属性append
。mcauth 给出的解决方案如下所示:
它工作得如此,因为生成的 SOAP 消息没有显示
arrayType
属性:我发现的最佳解决方案也是最简单的:
良好的 SOAP 消息结束:
它以 服务器端 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: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:
It works so so, as the resulting SOAP message shows no
arrayType
attribute:The best solution I found is also the simplest:
It ends with a good SOAP message:
as expected by the server side WS.
我相信您正在寻找的是:
我自己必须这样做;)帮助我找到它的是打印到控制台。 这可能会给你带来以下结果:
干杯,雅克
I believe what you are looking for is:
Just had to do this myself;) What helped me find it was printing to the console. That would have probably given you the following:
Cheers,Jacques
对于这种类型的结构,我在数组对象上设置了一个名为“item”的属性,然后将列表成员附加到它。 类似于:
即使对于具有多个级别的复杂调用,它也能很好地解析和传递。
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:
Which parses and passes in fine, even for complex calls with multiple levels.