Python-zeep: 'NoneType' object is not iterable for type of ArrayOfLong

Created on 28 Jun 2016  路  2Comments  路  Source: mvantellingen/python-zeep

Hi dear Michael,

Tnx a lot for zeep library.

I'm working on a project and use a web service that I attach it's wsdl file to this issue :

my_wsdl.txt

when I use "SendNumberGroup" method of service, then this error raised :

TypeError at /
'NoneType' object is not iterable

File of error described :
TypeError.htm.zip

the target web service developed with C# .Net and error raised for ArrayOfLong value.

my code in simple state :

        from zeep import Client
        import array

        WSDLPath = 'http://sms.mysite.com/SMSWS/SOAPWebService.asmx?wsdl'
        client = Client(WSDLPath)

        def SendSMSToGroup():
            groups = array.array('i', [38477411, 38477412]).tolist()
            client.service.SendNumberGroup(3364, 'myuser', 'mypassword', '', groups,
                                             'Hi dude!\rFrom site SMS Panel!!', '3000267010', False, True)
            return

and this one does not work too:

groups = [38477411, 38477412]

what's wrong ?

Most helpful comment

Hi,
I had a similar problem so I will try to help you, even if I am not sure I can be helpful

I think that groups which is an ArrayOfLong is a complex type on your server, thus you cannot simply send a python object.
In zeep there are two options:
you can get the object definition using

array_type = client.get_type('tns:ArrayOfLong')

and then create the object

groups = array_type(long=array.array('i', [38477411, 38477412]).tolist())
client.service.SendNumberGroup(3364, 'myuser', 'mypassword', '',groups,
                                             'Hi dude!\rFrom site SMS Panel!!', '3000267010', False, True)

or if you want to send the object direct you can send a dictionary thus

client.service.SendNumberGroup(3364, 'myuser', 'mypassword', '',{'long': groups},
                                             'Hi dude!\rFrom site SMS Panel!!', '3000267010', False, True)

In my examples I used 'long' as the attribute of ArrayOfLong as I found it checking on the Internet. Anyway if you use the first approach loading the type and then creating the object, you will get an error that lists the correct available attributes when you try to create an object using unexisting ones.

All 2 comments

Hi,
I had a similar problem so I will try to help you, even if I am not sure I can be helpful

I think that groups which is an ArrayOfLong is a complex type on your server, thus you cannot simply send a python object.
In zeep there are two options:
you can get the object definition using

array_type = client.get_type('tns:ArrayOfLong')

and then create the object

groups = array_type(long=array.array('i', [38477411, 38477412]).tolist())
client.service.SendNumberGroup(3364, 'myuser', 'mypassword', '',groups,
                                             'Hi dude!\rFrom site SMS Panel!!', '3000267010', False, True)

or if you want to send the object direct you can send a dictionary thus

client.service.SendNumberGroup(3364, 'myuser', 'mypassword', '',{'long': groups},
                                             'Hi dude!\rFrom site SMS Panel!!', '3000267010', False, True)

In my examples I used 'long' as the attribute of ArrayOfLong as I found it checking on the Internet. Anyway if you use the first approach loading the type and then creating the object, you will get an error that lists the correct available attributes when you try to create an object using unexisting ones.

Thanks dear @Colleoni

second solution works for me and service method run correctly.

with best regards to @mvantellingen

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orzilca picture orzilca  路  6Comments

ryan-mccaffrey picture ryan-mccaffrey  路  5Comments

ThreePinkApples picture ThreePinkApples  路  5Comments

ri8on picture ri8on  路  4Comments

alexfx picture alexfx  路  4Comments