Alpha Geek
Alpha Geek

Reputation: 489

Python-Twilio is not sending sms with test credential.

I have created trial account on twilio, and installed twilio using

pip install twilio

on ubuntu 14.04 LTS.

below is my python code to send the sms

from twilio.rest import TwilioRestClient

account_sid = "MY TEST ACCOUNT SID"
auth_token  = "MY TEST ACCOUNT TOKEN"
client = TwilioRestClient(account_sid, auth_token)
print "running!!"

sms = client.sms.messages.create(body="All in the game, yo",
    to="+91MYNUMBER",
    from_="+1MY_TWILIO_NUMBER")
print sms.sid
print sms.status

While running this python file I am getting below log error from twilio.

Traceback (most recent call last): File "/home/software/ws/extra/scripts/test.py", line 40, in from_="+1MY_TWILIO_NUMBER") File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/sms_messages.py", line 167, in create return self.create_instance(kwargs) File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 365, in create_instance data=transform_params(body)) File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 200, in request resp = make_twilio_request(method, uri, auth=self.auth, **kwargs) File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 164, in make_twilio_request uri=resp.url, msg=message, code=code) twilio.rest.exceptions.TwilioRestException: HTTP 400 error: The From phone number +1MY_TWILIO_NUMBER is not a valid, SMS-capable inbound phone number or short code for your account.

I have checked my number has Capabilities for Voice, SMS & MMS.

I have checked this error on here. then i tried with +15005550006 number, It is running but the i never receive the sms on my cell phone.the message went in queue which never processes.

runnnign!!
SM3f51b1c3e5ad43d38bd548cfada14175
queued

What I am missing? why I am not getting the sms?

Upvotes: 7

Views: 2037

Answers (2)

Vipul Khanna
Vipul Khanna

Reputation: 3

I used PHP to send the SMS from a trial account to a verified Indian number from a US number bought from Twilio. Didnt receive any message, though I can see the Sent status on the dashboard as well as on callbacks. Have opened a ticket to check.

Upvotes: 0

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

Test account credentials don't actually send SMS messages, they are test endpoints that let you know your HTTP calls are working as expected. That's why you have to use a specific number.

To test with the number you bought on your account you will need to use your real account credentials. Your Twilio trial account does come with some free credit to test these messages out before you need to upgrade, so I recommend changing to use those real credentials and the number you bought and you should start to see SMS messages coming through to your phone.

As a side note, the call to client.sms.messages.create actually uses a deprecated API. You can update that to client.messages.create and it will use the more modern Messages endpoint. (Side point on that though, the test credentials won't work at all with that endpoint, I still recommend using your real credentials and trial credit to test.)

Upvotes: 3

Related Questions