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

codevariable 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 thattonumber being fed from somewhere else in your code? Are you able to run this example code from the Twilio docs successfully?