2011-02-28 16 views
0

私はSudsに問題があり、どのような振る舞いをするのかわかりません。 私はwebserviceを呼び出そうとしており、そのサービスは 引数(ShippingGuideRequestType)として1つの複合型を取ります。私はpdbセッションを投稿し、 が何が起こっているのか説明しようとします。表示される 'request'変数はShippingGuideRequestTypeタイプで、 です。これはclient.factory.create( "ShippingGuideRequestType")を使用して作成されます。Sudsを使用しているPython SOAPに問題がある

(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はOKに見えますが、今のは、データと必要な フィールドを移入してみましょう。最初にUserInformationプロパティを扱いましょう。これはclient.factory.create( "UserInformationType")を使用して作成された です:

(Pdb) userInformation 
(UserInformationType){ 
    Usercode = "-CENCORED-" 
} 

今度は client.factory.create( "ProductIdsType")を使用して作成されProductIdsを処理してみましょう:

(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要素内ですべてがエンコードされるのはなぜですか?

shipping = client.factory.create("ShippingGuideRequestType") 

shipping.UserInformation.UserCode = val1 

shipping.RequestProperties.SchemaVersion = val2 
shipping.RequestProperties.Language = val3 

//Add the rest of the values. 

client.service.shippingFunction(shipping) 

答えて

関連する問題