Reputation: 21
Good evening! I apologize right away for my poor English.
I had a problem sending nested fields with the same name through zeep, zeep ignores all fields and sends only the last one.
I have such a function for zeep library,
def send_data(self, data):
response = self.client.service.GetAddrLetter(
Key = '12345',
AddrInfo={'RcpnName': data['recipient_name'],
'RcpnIndex': data['recipient_index'],
'RcpnPhone': data['recipient_phone'],
'RcpnEmail': '[email protected]',
'RcpnStreet': data['recipient_address'],
'SndrName': data['sender_name'],
'SndrPhone': data['sender_phone'],
'SndrIndex': data['sender_index'],
'SndrStreet': data['sender_address'],
'AddInfo':{'Field': data['request_order'], 'Field': data['old_order'], 'Field': data['new_order']},
)
return response
Data is a data dictionary that I take values from it and send it to the service.
Here's what a working request looks like, sending this request through a browser or soapui all fields are perfectly processed.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:pos="blabla">
<soapenv:Header/>
<soapenv:Body>
<pos:GetAddrLetterRequest>
<pos:Key>1234567</pos:Key>
<pos:AddrInfo>
<!--Optional:-->
<pos:RcpnName>Name Name</pos:RcpnName>
<pos:RcpnPhone>123456</pos:RcpnPhone>
<!--Optional:-->
<pos:RcpnEmail>mail@mail</pos:RcpnEmail>
<pos:RcpnStreet>my street</pos:RcpnStreet>
<pos:SndrName>shop_name</pos:SndrName>
<pos:SndrPhone>123456</pos:SndrPhone>
<pos:SndrStreet>my street</pos:SndrStreet>
<!--Optional:-->
<pos:AddInfo>
<!--0 to 5 repetitions:-->
<pos:Field>111</pos:Field>
<pos:Field>222</pos:Field>
<pos:Field>333</pos:Field>
</pos:AddInfo>
</pos:AddrInfo>
</pos:GetAddrLetterRequest>
</soapenv:Body>
</soapenv:Envelope>
Upvotes: 1
Views: 976
Reputation: 11
There is a way that you can add as an array. The zeep will convert the array values into the repeated element format.
field_value = [111,222,333]
Then zeep will take it as
<pos:AddInfo>
<pos:Field>111</pos:Field>
<pos:Field>222</pos:Field>
<pos:Field>333</pos:Field>
</pos:AddInfo>
Upvotes: 1
Reputation: 21
Good evening, after long hours of torment, I solved this problem, I can’t say that my solution is elegant or correct, but it works and this is the most important thing for me now.
I studied this part of the manual in the library, but alas, none of the solutions to the nested tags helped me
Then I did the following, I just pulled out the fields I needed from the dictionary and using concatenation added it to the field I needed.
def send_data(self, data):
request_order = str(data['request_order'])
old_order = str(data['old_order'])
new_order = str(data['new_order'])
field_value = request_order + '\n' + old_order + '\n' + new_order
response = self.client.service.GetAddrLetter(
Key = '12345',
AddrInfo={'RcpnName': data['recipient_name'],
'RcpnIndex': data['recipient_index'],
'RcpnPhone': data['recipient_phone'],
'RcpnEmail': '[email protected]',
'RcpnStreet': data['recipient_address'],
'SndrName': data['sender_name'],
'SndrPhone': data['sender_phone'],
'SndrIndex': data['sender_index'],
'SndrStreet': data['sender_address'],
'AddInfo':{'Field': field_value },
)
return response
Now everything works, I apologize for the bad code, I'm just a junior developer, I hope this can be useful to someone
Upvotes: 1