简体   繁体   English

python中的Twilio短信发送器API不起作用

[英]Twilio sms sender api in python does not work

My code: 我的代码:

from twilio.rest import Client

# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.api.account.messages.create(
    to="+#############",
    from_="+###########",
    body="Hello there!")

The error which I get: 我得到的错误:

Traceback (most recent call last):
  File "C:\Users\Keshavarz\Desktop\twilio1.py", line 14, in <module>
    body='Hello there!'
  File "C:\Users\Keshavarz\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twilio\rest\api\v2010\account\message\__init__.py", line 92, in create
    data=data,
  File "C:\Users\Keshavarz\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twilio\base\version.py", line 209, in create
    raise self.exception(method, uri, response, 'Unable to create record')
twilio.base.exceptions.TwilioRestException: 
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m

[36m[49mPOST /Accounts/AC2b7b52ba2fc52a5eebf2c060257f7a7c/Messages.json[0m

[37m[49mTwilio returned the following information:[0m

[34m[49mUnable to create record[0m

[37m[49mMore information may be available here:[0m

[34m[49mhttps://www.twilio.com/docs/errors/451[0m

I meet all things to make SID and Authentication token based on this link but I could not send any SMS to my cell phone # 我满足了基于此链接制作SID和身份验证令牌的所有要求,但无法将任何短信发送至我的手机#

Twilio developer evangelist here. Twilio开发人员布道者在这里。

There is a URL in that response that should help explain what's going on. 该响应中有一个URL,该URL应该有助于解释发生了什么。 Sadly it seems to have been garbled somewhat in the log. 可悲的是,它似乎在日志中有些乱码。

What I'd suggest is that you catch the error and try to print it another way. 我建议您发现错误并尝试以其他方式打印它。 Try this and see what the result is: 试试看,看看结果是什么:

client = Client(account_sid, auth_token)
try:
    client.api.account.messages.create(
        to="+#############",
        from_="+###########",
        body="Hello there!")
except TwilioRestException as ex:
    print(ex)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM