使用 Suds 使用 Python SOAP 时遇到问题
我在使用肥皂水时遇到了问题,我不明白是什么导致了它的行为如此。 我正在尝试调用一个 Web 服务,该服务采用一种复杂类型作为 参数(ShippingGuideRequestType)。我将发布我的 pdb 会话并尝试解释什么 正在发生。您看到的“请求”变量的类型为 ShippingGuideRequestType 并且 它是使用 client.factory.create("ShippingGuideRequestType") 创建的。
(Pdb) request
(ShippingGuideRequestType){
UserInformation =
(UserInformationType){
Usercode = None
}
RequestProperties =
(RequestPropertiesType){
SchemaVersion = None
Language = None
WithPrice = None
WithExpectedDelivery = None
WithGuiInformation = None
NumberOfAlternativeDeliveryDates = None
EDI = None
PostingAtPostoffice = None
Trace = None
}
ProductIds =
(ProductIdsType){
ProductId[] = <empty>
}
Consignment =
(ConsignmentInputType){
FromCountryCode = None
FromPostalCode = None
ToCountryCode = None
ToPostalCode = None
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
EarlyCollectionAtTerminal = None
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
}
Packages =
(PackagesInputType){
Package[] = <empty>
}
}
ShippingGuideRequestType 看起来不错,现在让我们尝试填充所需的 带有数据的字段。我们首先处理 UserInformation 属性。这是 使用 client.factory.create("UserInformationType") 创建:
(Pdb) userInformation
(UserInformationType){
Usercode = "-CENCORED-"
}
现在让我们处理使用以下命令创建的 ProductIds client.factory.create("ProductIdsType"):
(Pdb) productsInput
(ProductIdsType){
ProductId[] =
"SERVICEPAKKE",
}
最后一个必需的属性是 PackagesInputType,这是稍后创建的 更复杂的方式。首先,我创建 PackagesInputType,然后创建一个数组 PackageInputType(使用 client.factory.create("PackageInputType"))。
(Pdb) packagesInput
(PackagesInputType){
Package[] =
(PackageInputType){
Height =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Width =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Length =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
GrossWeight =
(UnitCodeWeightType){
value = 1000
_unitCode = "GRM"
}
Volume =
(UnitCodeCubicType){
value = None
_unitCode = "DMQ"
}
VolumeSpecial = None
FromCountryCode = None
FromPostalCode = "7800"
ToCountryCode = None
ToPostalCode = "7041"
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
EarlyCollectionAtTerminal = None
_packageId = "myRef"
},
}
(Pdb) request.UserInformation = userInformation
(Pdb) request.ProductIds = productsInput
(Pdb) request.Packages = packagesInput
(Pdb) request
(ShippingGuideRequestType){
UserInformation =
(UserInformationType){
Usercode = "-CENCORED"
}
RequestProperties =
(RequestPropertiesType){
SchemaVersion = None
Language = None
WithPrice = None
WithExpectedDelivery = None
WithGuiInformation = None
NumberOfAlternativeDeliveryDates = None
EDI = None
PostingAtPostoffice = None
Trace = None
}
ProductIds =
(ProductIdsType){
ProductId[] =
"SERVICEPAKKE",
}
Consignment =
(ConsignmentInputType){
FromCountryCode = None
FromPostalCode = None
ToCountryCode = None
ToPostalCode = None
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
EarlyCollectionAtTerminal = None
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
}
Packages =
(PackagesInputType){
Package[] =
(PackageInputType){
Height =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Width =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Length =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
GrossWeight =
(UnitCodeWeightType){
value = 1000
_unitCode = "GRM"
}
Volume =
(UnitCodeCubicType){
value = None
_unitCode = "DMQ"
}
VolumeSpecial = None
FromCountryCode = None
FromPostalCode = "7800"
ToCountryCode = None
ToPostalCode = "7041"
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
EarlyCollectionAtTerminal = None
_packageId = "myRef"
},
}
}
在我看来,结构看起来不错,现在让我们尝试调用该服务。
(Pdb) self.client.service.ShippingGuide(request)
2011-02-28 14:32:37 ERROR suds.client <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://www.bring.no/logistics/shippingguide/1.0" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:ShippingGuideRequest>
<ns0:UserInformation>
<ns0:UserInformation>
<ns0:Usercode>-CENCORED-</ns0:Usercode>
</ns0:UserInformation>
<ns0:RequestProperties>
<ns0:SchemaVersion/>
</ns0:RequestProperties>
<ns0:ProductIds>
<ns0:ProductId>SERVICEPAKKE</ns0:ProductId>
</ns0:ProductIds>
<ns0:Packages>
<ns0:Package packageId="myRef">
<ns0:Height unitCode="CMT">10</ns0:Height>
<ns0:Width unitCode="CMT">10</ns0:Width>
<ns0:Length unitCode="CMT">10</ns0:Length>
<ns0:GrossWeight unitCode="GRM">1000</ns0:GrossWeight>
<ns0:Volume unitCode="DMQ"/>
<ns0:FromCountryCode/>
<ns0:FromPostalCode>7800</ns0:FromPostalCode>
<ns0:ToCountryCode/>
<ns0:ToPostalCode>7041</ns0:ToPostalCode>
</ns0:Package>
</ns0:Packages>
</ns0:UserInformation>
<ns0:RequestProperties/>
<ns0:ProductIds/>
<ns0:Packages/>
</ns0:ShippingGuideRequest>
</ns1:Body>
</SOAP-ENV:Envelope>
*** WebFault: Server raised fault: 'FG_INPUT_003 User information missing from request. [errorId cf19f72b-0795-4f58-8a70-a8c1846ba186]'
这里发生了什么?为什么所有内容都编码在 UserInformation 元素中?
I'm having problems with Suds and I can't figure out what makes it behave like this.
I'm trying to call a webservice and that service takes one complex type as an
argument (ShippingGuideRequestType). I'll post my pdb session and try to explain what
is happening. The 'request' variable you see is of type ShippingGuideRequestType and
it is created using client.factory.create("ShippingGuideRequestType").
(Pdb) request
(ShippingGuideRequestType){
UserInformation =
(UserInformationType){
Usercode = None
}
RequestProperties =
(RequestPropertiesType){
SchemaVersion = None
Language = None
WithPrice = None
WithExpectedDelivery = None
WithGuiInformation = None
NumberOfAlternativeDeliveryDates = None
EDI = None
PostingAtPostoffice = None
Trace = None
}
ProductIds =
(ProductIdsType){
ProductId[] = <empty>
}
Consignment =
(ConsignmentInputType){
FromCountryCode = None
FromPostalCode = None
ToCountryCode = None
ToPostalCode = None
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
EarlyCollectionAtTerminal = None
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
}
Packages =
(PackagesInputType){
Package[] = <empty>
}
}
The ShippingGuideRequestType looks OK, now let's try to populate the required
fields with data. Let's first deal with the UserInformation property. This is
created using client.factory.create("UserInformationType"):
(Pdb) userInformation
(UserInformationType){
Usercode = "-CENCORED-"
}
Now let's handle the ProductIds which is created using
client.factory.create("ProductIdsType"):
(Pdb) productsInput
(ProductIdsType){
ProductId[] =
"SERVICEPAKKE",
}
The final required property is the PackagesInputType, this is created in a bit
more complex manner. First I create the PackagesInputType, then I create an array
of PackageInputType (using client.factory.create("PackageInputType")).
(Pdb) packagesInput
(PackagesInputType){
Package[] =
(PackageInputType){
Height =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Width =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Length =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
GrossWeight =
(UnitCodeWeightType){
value = 1000
_unitCode = "GRM"
}
Volume =
(UnitCodeCubicType){
value = None
_unitCode = "DMQ"
}
VolumeSpecial = None
FromCountryCode = None
FromPostalCode = "7800"
ToCountryCode = None
ToPostalCode = "7041"
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
EarlyCollectionAtTerminal = None
_packageId = "myRef"
},
}
(Pdb) request.UserInformation = userInformation
(Pdb) request.ProductIds = productsInput
(Pdb) request.Packages = packagesInput
(Pdb) request
(ShippingGuideRequestType){
UserInformation =
(UserInformationType){
Usercode = "-CENCORED"
}
RequestProperties =
(RequestPropertiesType){
SchemaVersion = None
Language = None
WithPrice = None
WithExpectedDelivery = None
WithGuiInformation = None
NumberOfAlternativeDeliveryDates = None
EDI = None
PostingAtPostoffice = None
Trace = None
}
ProductIds =
(ProductIdsType){
ProductId[] =
"SERVICEPAKKE",
}
Consignment =
(ConsignmentInputType){
FromCountryCode = None
FromPostalCode = None
ToCountryCode = None
ToPostalCode = None
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
EarlyCollectionAtTerminal = None
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
}
Packages =
(PackagesInputType){
Package[] =
(PackageInputType){
Height =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Width =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
Length =
(UnitCodeLengthType){
value = 10
_unitCode = "CMT"
}
GrossWeight =
(UnitCodeWeightType){
value = 1000
_unitCode = "GRM"
}
Volume =
(UnitCodeCubicType){
value = None
_unitCode = "DMQ"
}
VolumeSpecial = None
FromCountryCode = None
FromPostalCode = "7800"
ToCountryCode = None
ToPostalCode = "7041"
ShippingDate =
(DateAndTimeType){
Year = None
Month = None
Day = None
Hour = None
Minute = None
}
AdditionalServices =
(AdditionalServicesInputType){
AdditionalService[] = <empty>
}
EarlyCollectionAtTerminal = None
_packageId = "myRef"
},
}
}
In my point of view the structure looks fine, now let's try to call the service.
(Pdb) self.client.service.ShippingGuide(request)
2011-02-28 14:32:37 ERROR suds.client <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://www.bring.no/logistics/shippingguide/1.0" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:ShippingGuideRequest>
<ns0:UserInformation>
<ns0:UserInformation>
<ns0:Usercode>-CENCORED-</ns0:Usercode>
</ns0:UserInformation>
<ns0:RequestProperties>
<ns0:SchemaVersion/>
</ns0:RequestProperties>
<ns0:ProductIds>
<ns0:ProductId>SERVICEPAKKE</ns0:ProductId>
</ns0:ProductIds>
<ns0:Packages>
<ns0:Package packageId="myRef">
<ns0:Height unitCode="CMT">10</ns0:Height>
<ns0:Width unitCode="CMT">10</ns0:Width>
<ns0:Length unitCode="CMT">10</ns0:Length>
<ns0:GrossWeight unitCode="GRM">1000</ns0:GrossWeight>
<ns0:Volume unitCode="DMQ"/>
<ns0:FromCountryCode/>
<ns0:FromPostalCode>7800</ns0:FromPostalCode>
<ns0:ToCountryCode/>
<ns0:ToPostalCode>7041</ns0:ToPostalCode>
</ns0:Package>
</ns0:Packages>
</ns0:UserInformation>
<ns0:RequestProperties/>
<ns0:ProductIds/>
<ns0:Packages/>
</ns0:ShippingGuideRequest>
</ns1:Body>
</SOAP-ENV:Envelope>
*** WebFault: Server raised fault: 'FG_INPUT_003 User information missing from request. [errorId cf19f72b-0795-4f58-8a70-a8c1846ba186]'
What happened here? Why is everything encoded within the UserInformation element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有尝试过:
Have you give this a go: