Convert python array of int to SOAP ArrayofInt

1.5k Views Asked by At

I am using the zeep python package so as to call a function through SOAP which accepts an argument of 'ArrayofInt' type.

Passing a 'normal' integer array doesn't work... the workaround is to run through the elements of the array with a for loop and send the elements one-by-one but this is not the cleanest code I have ever written:)

Any suggestions?

3

There are 3 best solutions below

0
On BEST ANSWER

This answer will sort you out.

Use the Zeep's client.get_type function to create an empty Zeep ArrayOfInt object and then loop your array through it.

client = Client(soap_url)
test_list = [1,2,3,4]
emptyArrayPlaceholder = client.get_type('ns0:ArrayOfInt')
options = emptyArrayPlaceholder()

for el in test_list:
    options['int'].append(el)
0
On

If your method in SOAP service accept an array of integer as argument then you can try this way:

clientInt = Client(wsdl)
list_int=[1,2,3]
dict_int = {"ArrayOfInteger":{"integer":list_int}}
clientInt.service.getMultipleInt(**dict_int)

when you pass **dict_int as the argument, python3 will unpack the dictionary and pass the keyword in the dictionary as the function argument.

0
On

If you are unable to retrieve object from wsdl try this:

client = Client(soap_url)
test_list = [1,2,3,4]
client.service.ServiceName({"foo": {"int": test_list}})