我尝试在 Python 2 中使用 Twilio 发送短信
I tried to send an SMS using Twilio in Python 2
我在Python2中写了一个代码来发送短信,但是我收到了一个错误。
from Twilio.rest import Client
# Your Account SID from twilio.com/console
account_sid = "secret"
# Your Auth Token from twilio.com/console
auth_token = "secret"
client = Client(account_sid, auth_token)
message = client.messages.create(
to="", #a number
from_="", #twilio's numbe
body="welcome to zadly")
print(message.sid)
我预计我会收到短信,但我的输出是
Traceback (most recent call last):
File "C:\Python27\send_sms.py", line 13, in <module>
body="welcome to zadly")
File "C:\Python27\lib\site-packages\twilio\rest\api\v2010\account\message\__init__.py", line 87, in create
data=data,
File "C:\Python27\lib\site-packages\twilio\base\version.py", line 209, in create
raise self.exception(method, uri, response, 'Unable to create record')
TwilioRestException:
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m
[36m[49mPOST /Accounts/ACe927e239a57716562b26844cf015dda8/Messages.json[0m
[37m[49mTwilio returned the following information:[0m
[34m[49mUnable to create record: Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +966509493238.[0m
[37m[49mMore information may be available here:[0m
[34m[49mhttps://www.twilio.com/docs/errors/21408[0m
打开 this 并阅读此内容 -
If you wish to send messages to this region, please enable the relevant permissions on your account in the Global Permissions page.
现在点击全局权限 link并启用发送短信的相关权限。比较简单。
Ps: 请务必仔细阅读您的例外情况,其中有线索 ;)
我在Python2中写了一个代码来发送短信,但是我收到了一个错误。
from Twilio.rest import Client
# Your Account SID from twilio.com/console
account_sid = "secret"
# Your Auth Token from twilio.com/console
auth_token = "secret"
client = Client(account_sid, auth_token)
message = client.messages.create(
to="", #a number
from_="", #twilio's numbe
body="welcome to zadly")
print(message.sid)
我预计我会收到短信,但我的输出是
Traceback (most recent call last):
File "C:\Python27\send_sms.py", line 13, in <module>
body="welcome to zadly")
File "C:\Python27\lib\site-packages\twilio\rest\api\v2010\account\message\__init__.py", line 87, in create
data=data,
File "C:\Python27\lib\site-packages\twilio\base\version.py", line 209, in create
raise self.exception(method, uri, response, 'Unable to create record')
TwilioRestException:
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m
[36m[49mPOST /Accounts/ACe927e239a57716562b26844cf015dda8/Messages.json[0m
[37m[49mTwilio returned the following information:[0m
[34m[49mUnable to create record: Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +966509493238.[0m
[37m[49mMore information may be available here:[0m
[34m[49mhttps://www.twilio.com/docs/errors/21408[0m
打开 this 并阅读此内容 -
If you wish to send messages to this region, please enable the relevant permissions on your account in the Global Permissions page.
现在点击全局权限 link并启用发送短信的相关权限。比较简单。
Ps: 请务必仔细阅读您的例外情况,其中有线索 ;)