Python Suds - 关于将项目添加到数组的困惑
Python Suds - Confusion About Adding Item to Array
我正在尝试生成一个肥皂水请求,其中包含一系列项目。我无法正确插入数组,我尝试的一切只是将数组容器设置为数组项。
我试过设置和追加相同的结果。
Python代码
add_request = client.factory.create('AddRequest')
add_request_identity = client.factory.create('Identity')
add_request_identity.NameTypeCode = '06'
add_request_identity.ApplicationIdentityIdentifier = 'true'
add_request_identity.FamilyName = 'Fname98765432000'
add_request_identity.GivenNames = 'Gname98765432000'
add_request_identity.Gender = '01'
add_request_identity.DateOfBirth = '1990-06-27'
add_request_identity.DateOfBirthType = 'ACTUAL'
add_request_identity.PlaceOfBirth = 'OTTAWA'
add_request_identity.CountryOfBirth = 'CAN'
add_request.Identity = [add_request_identity]
我也试过了
add_request.Identity = add_request_identity
add_request.Identity.append(add_request_identity)
(this throws an error "suds AttributeError: 'ArrayOfIdentity' object has no attribute 'append'")
add_request.Identity = []
add_request.Identity.append(add_request_identity)
add_request_identity_array = client.factory.create('ArrayOfIdentity')
add_request_identity_array = [add_request_identity]
add_request.Identity = add_request_identity_array
但它们都产生相同的输出
实际产量
<ns0:Add>
<ns0:Request>
<ns0:Identity>
<ns0:NameTypeCode>06</ns0:NameTypeCode>
<ns0:ApplicationIdentityIdentifier>true</ns0:ApplicationIdentityIdentifier>
<ns0:FamilyName>Fname98765432000</ns0:FamilyName>
<ns0:GivenNames>Gname98765432000</ns0:GivenNames>
<ns0:Gender>01</ns0:Gender>
<ns0:DateOfBirth>1990-06-27</ns0:DateOfBirth>
<ns0:DateOfBirthType>ACTUAL</ns0:DateOfBirthType>
<ns0:PlaceOfBirth>OTTAWA</ns0:PlaceOfBirth>
<ns0:CountryOfBirth>CAN</ns0:CountryOfBirth>
</ns0:Identity>
我想要得到的(这是用 SoapUI 生成的)
<v1:Add>
<v1:Request>
<v1:Identity>
<!--1 or more repetitions:-->
<v1:Identity>
<v1:NameTypeCode>06</v1:NameTypeCode>
<v1:ApplicationIdentityIdentifier>true</v1:ApplicationIdentityIdentifier>
<v1:FamilyName>Fname234567022</v1:FamilyName>
<v1:GivenNames>Gname234567022</v1:GivenNames>
<v1:Gender>01</v1:Gender>
<v1:DateOfBirth>1990-06-27</v1:DateOfBirth>
<v1:DateOfBirthType>ACTUAL</v1:DateOfBirthType>
<!--Optional:-->
<v1:PlaceOfBirth>OTTAWA</v1:PlaceOfBirth>
<!--Optional:-->
<v1:CountryOfBirth>CAN</v1:CountryOfBirth>
</v1:Identity>
</v1:Identity>
我能够自己解决这个问题。顶部标识元素有一个子标识元素。
add_request_identity_array = client.factory.create('ArrayOfIdentity')
add_request_identity_array.Identity = [add_request_identity1, add_request_identity2]
add_request.Identity = add_request_identity_array
或
add_request.Identity.Identity = [add_request_identity1, add_request_identity2]
我正在尝试生成一个肥皂水请求,其中包含一系列项目。我无法正确插入数组,我尝试的一切只是将数组容器设置为数组项。
我试过设置和追加相同的结果。
Python代码
add_request = client.factory.create('AddRequest')
add_request_identity = client.factory.create('Identity')
add_request_identity.NameTypeCode = '06'
add_request_identity.ApplicationIdentityIdentifier = 'true'
add_request_identity.FamilyName = 'Fname98765432000'
add_request_identity.GivenNames = 'Gname98765432000'
add_request_identity.Gender = '01'
add_request_identity.DateOfBirth = '1990-06-27'
add_request_identity.DateOfBirthType = 'ACTUAL'
add_request_identity.PlaceOfBirth = 'OTTAWA'
add_request_identity.CountryOfBirth = 'CAN'
add_request.Identity = [add_request_identity]
我也试过了
add_request.Identity = add_request_identity
add_request.Identity.append(add_request_identity)
(this throws an error "suds AttributeError: 'ArrayOfIdentity' object has no attribute 'append'")
add_request.Identity = []
add_request.Identity.append(add_request_identity)
add_request_identity_array = client.factory.create('ArrayOfIdentity')
add_request_identity_array = [add_request_identity]
add_request.Identity = add_request_identity_array
但它们都产生相同的输出
实际产量
<ns0:Add>
<ns0:Request>
<ns0:Identity>
<ns0:NameTypeCode>06</ns0:NameTypeCode>
<ns0:ApplicationIdentityIdentifier>true</ns0:ApplicationIdentityIdentifier>
<ns0:FamilyName>Fname98765432000</ns0:FamilyName>
<ns0:GivenNames>Gname98765432000</ns0:GivenNames>
<ns0:Gender>01</ns0:Gender>
<ns0:DateOfBirth>1990-06-27</ns0:DateOfBirth>
<ns0:DateOfBirthType>ACTUAL</ns0:DateOfBirthType>
<ns0:PlaceOfBirth>OTTAWA</ns0:PlaceOfBirth>
<ns0:CountryOfBirth>CAN</ns0:CountryOfBirth>
</ns0:Identity>
我想要得到的(这是用 SoapUI 生成的)
<v1:Add>
<v1:Request>
<v1:Identity>
<!--1 or more repetitions:-->
<v1:Identity>
<v1:NameTypeCode>06</v1:NameTypeCode>
<v1:ApplicationIdentityIdentifier>true</v1:ApplicationIdentityIdentifier>
<v1:FamilyName>Fname234567022</v1:FamilyName>
<v1:GivenNames>Gname234567022</v1:GivenNames>
<v1:Gender>01</v1:Gender>
<v1:DateOfBirth>1990-06-27</v1:DateOfBirth>
<v1:DateOfBirthType>ACTUAL</v1:DateOfBirthType>
<!--Optional:-->
<v1:PlaceOfBirth>OTTAWA</v1:PlaceOfBirth>
<!--Optional:-->
<v1:CountryOfBirth>CAN</v1:CountryOfBirth>
</v1:Identity>
</v1:Identity>
我能够自己解决这个问题。顶部标识元素有一个子标识元素。
add_request_identity_array = client.factory.create('ArrayOfIdentity')
add_request_identity_array.Identity = [add_request_identity1, add_request_identity2]
add_request.Identity = add_request_identity_array
或
add_request.Identity.Identity = [add_request_identity1, add_request_identity2]