marcuz / libpynexmo

Python library to interact with Nexmo SMS API
BSD 2-Clause "Simplified" License
63 stars 34 forks source link

Can't iterate and create new NexmoMessage objects, REST calls #2

Closed mwhawkins closed 12 years ago

mwhawkins commented 12 years ago

When trying to iterate through an array of recipients (for x in array), I tried to create new NexmoMessage objects for each and call the REST API, but I get the "'builtin_function_or_method' object is unsubscriptable" error. It appears there is a builtin function being used that won't allow the iteration to perform.

mwhawkins commented 12 years ago

Sample code giving the error:

msg = {'reqtype':'json','password':'12345','from':'123456789','username':'12345','to':'123456789'} for t in self.get_text_recipients():
msg['to'] = t sms = NexmoMessage(msg) sms.set_text_info(self.content) sms.send_request()

marcuz commented 12 years ago

Hello Michael,

thank you for your feedback, I'm going to look into this issue as soon as possible!

Cheers!

marcuz commented 12 years ago

Michael,

I guess the problem resides in "get_text_recipients()". What does that function return? I tried to simulate it using this code:

#!/usr/bin/env python

from nexmomessage import NexmoMessage

def get_text_recipients():
    return ["+391234567890", "+391234567891"]

msg = {'reqtype':'json','password':'blablabla','from':'123456789',
           'username':'blablabla','to':'123456789'}
content = "fool the reader"

for t in get_text_recipients():
    msg['to'] = t
    sms = NexmoMessage(msg)
    sms.set_text_info(content)
    print sms.get_details()
    print sms.send_request()

and I got both texts delivered instantly.

Please let me know! :)

mwhawkins commented 12 years ago

Yeah - really sorry about this - turns out it was a Django model object I couldn't iterate on and it was being passed in the get_text_recipients function. Really, really sorry about that.

marcuz commented 12 years ago

No problem at all! :)

I'll close this issue, have a good time!