Reputation: 47
I am using windows 10 and I want to use twilio API , so first by terminal I installed the twilio and the install success , then to check every thing ok I run this code :
import twilio
print twilio.__version__
the output is : 5.7.0
Now I want to send message to my phone , I signup and get my account_sid ,auth_token , twilio number and register in my phone number which I want to send message to it , I try to run this code after I replaced my account_sid ,auth_token , twilio number and register in my phone number But it give exeception this is the code :
from twilio.rest import TwilioRestClient
import twilio
print twilio.__version__
# Your Account SID from twilio.com/console
account_sid = "AC6791725bc93116fbd42b4cd477996f7d"
# Your Auth Token from twilio.com/console
auth_token = "30ed212f6a2bbc05d103b67426b8509a"
client = TwilioRestClient(account_sid, auth_token)
message = client.sms.messages.create(
body="Sent from your Twilio trial account - hello from python",
to="my number phone goes here",
from_="+14695356845" )
print message.sid
the runtime error :
Traceback (most recent call last):
File "C:/Users/Black_Swan/PycharmProjects/omac1/send message.py", line 14, in <module>
from_="+14695356845" )
File "C:\Python27\lib\site-packages\twilio\rest\resources\sms_messages.py", line 167, in create
return self.create_instance(kwargs)
File "C:\Python27\lib\site-packages\twilio\rest\resources\base.py", line 365, in create_instance
data=transform_params(body))
File "C:\Python27\lib\site-packages\twilio\rest\resources\base.py", line 200, in request
resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "C:\Python27\lib\site-packages\twilio\rest\resources\base.py", line 164, in make_twilio_request
uri=resp.url, msg=message, code=code)
twilio.rest.exceptions.TwilioRestException: HTTP 451 error: IP Address: 5.0.217.104
any help what I do mistake ?
Upvotes: 1
Views: 397
Reputation: 685
First, I encourage you to use Python 3 instead Python 2, you'll be a better person.
About the error, it returns a 451 http error, doing a quick search in Google, I got this: HTTP 451 Unavailable For Legal Reasons
I'm going to give you possible solutions:
Check if your phone can send messages: Go to Dashboard -> Phone Numbers - Manage Numbers -> Click on your Twilio number. Here on the bottom you can see in "Messaging" if you can send SMS. I can't and I have a "Messaging is unavailable for this phone number." message.
Check if you have your country enable to send SMS: SMS Geographic Permissions link.
The other option (and most likely) is that Twilio can't send you SMS to your country for legal reasons. Here you can check if there is any problem with sending messages from your Twilio phone to your phone country.
I hope it helps
Upvotes: 2