pythontwiliosmstwilio-apitwilio-python

Twilio SMS is saying a "to" phone number is not provided even though it is


I have very simple code and I just can't figure out what's going wrong.

I have a Twilio trial account and a trial phone number and I am trying to send an SMS using it.

from os import environ
from twilio.rest import Client

client = Client(environ['ACCOUNT_SID'], environ['AUTH_TOKEN'])

message = client.messages.create(body = f'The verification code for Treal is {code}', from_ = "+1**********", to = "+91**********")

The one in the from is my Twilio trial number and the one in the "to" is a number I want to send to. I am getting an error:

twilio.base.exceptions.TwilioRestException:
HTTP Error Your request was:

POST /Accounts/AC*******1830e0****a3403dfd16d****/Messages.json

Twilio returned the following information:

Unable to create record: A 'To' phone number is required.

More information may be available here:

https://www.twilio.com/docs/errors/21604

Solution

  • With a trial account, in Twilio, you can send a message only to the phone you signed in with or verified so if I provided the phone number "1234" I can only send messages to "1234".

    Maybe you didn't provide a phone number when you signed up?

    Twiilo docs docs pic