Forums

AttributeError in Twilio (sms send not working)

Below is my code:

from twilio.rest import TwilioRestClient

account_sid = "Axxxxxxxxxx"
auth_token = "6xxxxxxxxxxxx"
client = TwilioRestClient(account_sid, auth_token)

message = client.sms.message.create(
body="Hi! How r u?",
to="+92343513****", # Replace with your phone number
from_="+49 15735984005") # Replace with your Twilio number
print message.sid

And this is what I get, when I tried running my Program:

Traceback (most recent call last):
File "/home/mubeen/Desktop/Udacity/Python_Programs/send_text.py", line 7, in 
message = client.sms.message.create(
AttributeError: 'Sms' object has no attribute 'message'

Please help me out, I am stuck. Thank you.

[edited by admin: formatting]

Have you taken a look at the twilio documentation?

from twilio.rest import TwilioRestClient

# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(to="+12316851234", from_="+15555555555",
                                     body="Hello there!")

Yes I did looked at twilio doc, but even your code didn't work for me. It gives the following error: AttributeError: "TwilioRestClient" object has no attribute "message"

The attribute on the client is messages, not message