Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 914
Alpha Geek Avatar asked Dec 16 '15 07:12

Alpha Geek


People also ask

Why is Twilio not sending SMS?

Two common reasons for this: You might be trying to send SMS from a phone number which is only enabled for voice. This list shows which Twilio phone numbers are SMS enabled. All other Twilio phone numbers are not capable of sending SMS messages.

Does Twilio send text messages when using test credentials?

I never received any messages or calls when using test credentials. Test credentials only provide a way for you to "pretend" sending a message or making a phone call. Twilio will not charge your project, nor will the actions be performed.

Why can't I send SMS from my Twilio phone number?

All other Twilio phone numbers are not capable of sending SMS messages. You might be trying to send SMS from a number you have verified with Twilio. Twilio will only allow you to do this with phone calls, not SMS. You can learn more here.

Why my Twilio number doesn't work as the from parameter?

My Twilio number doesn't work as the From parameter. Your test credentials don't have access to any valid 'From' phone numbers on your production project.

How does Twilio validate API requests?

Learn more about status callbacks for SMS and status callbacks for Voice. When you make an API request with your test credentials, Twilio will validate all input as though the request were made with your real credentials. However, there are some cases when a request's validity depends on the state of Twilio.


1 Answers

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.)

like image 197
philnash Avatar answered Oct 13 '22 00:10

philnash