0

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
13
  • Are you sure the phone number you gave is valid? Commented Feb 9, 2022 at 9:15
  • @tomerpacific Yes. There are no asterisks in the real phone_numbers, I just added that to hide them since it is unsafe to disclose my phone number. Commented Feb 9, 2022 at 9:17
  • I understand there are no real asterisks in the real phone number, but since I cannot see the full phone number, I suggested that it might not be a valid one. Commented Feb 9, 2022 at 11:59
  • Yeah, I get it. I had upvoted your answer Commented Feb 9, 2022 at 12:48
  • As far as I can see, the code you shared isn't the full code you are running, as the code variable is only mentioned in the formatted string. I appreciate cutting an example down, but I wonder if you cut out where the bug is here. Is that to number being fed from somewhere else in your code? Are you able to run this example code from the Twilio docs successfully? Commented Feb 10, 2022 at 2:24

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I did, but I am trying to sms a different phone number. Let me check if it works with my phone number which I registered with.
ok let me know if it works
nope. still doesn't work. The error message say the to field was absent, so I think that's it, it's not receiving the 'to' field.
I have the same code and it's working for me maybe test again if the number was verified, or test if the phone prefix is right.
1

Check for hidden control characters using a site like https://www.soscisurvey.de/tools/view-chars.php, and simply using a regular string, and see if it works or not and then work to failure.

2 Comments

Nope. No hidden characters.
And you removed the string formatting to see if that worked?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.