我使用Twilio运行了发送文本的示例代码,代码来自:https://www.twilio.com/docs/libraries/python 我的代码是:
from twilio.rest import TwilioRestClient,
account_sid = "{{ Account 510 from www.twilio.com/console }}"
auth_token = "{{ Auth Token from www.twilio.com/console }}"
client = TwilioRestClient(account_sid, auth_token)
message = clientmessages.create(body="You are the best!",
to="your phone number",
from_="your Twilio number")
print(message.sid)
我已经安装了twilio,使用pip,为什么会出现这个问题,请帮助〜 有一份我的代码:
from twilio.rest import TwilioRestClient;
account_sid = "{{ ACCOUNT_SID }}" # Your Account SID from www.twilio.com/console
auth_token = "{{ AUTH_TOKEN }}" # Your Auth Token from www.twilio.com/console
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(body="You are the best!",
to="+phonenumber", # Replace with your phone number
from_="+(201) ") # Replace with your Twilio number
print(message.sid)
答案 0 :(得分:21)
Twilio开发者传道者在这里。
我知道您已经通过将库的版本从6.0更改为5.6.0来回答自己,但这就是提醒我实际问题的原因!
使用Twilio Python helper library版本6.0时,您需要导入Client
而不是TwilioRestClient
。
我想知道您是否有文档集来显示5.6.0库示例。如果您想使用6.0(您应该使用它是最新的),请确保您在文档中选择了最新版本。请参阅下图,了解如何选择它。
答案 1 :(得分:5)
我知道什么是错的。 当错误发生时,twilio的版本是6.0;我尝试更改twilio的版本,我将其更改为5.6.0,没有错误显示。
答案 2 :(得分:2)
我正在使用twilio版本6 +
当我尝试使用twiliorestclient甚至得到与提及上层相同的错误时,现在我正在尝试这个,这解决了我的问题甚至
from twilio.rest import Client
#Your Account SID from twilio.com/console
account_sid = "" #your account SID from twilio console
#Your Auth Token from twilio.com/console
auth_token = "" #your auth token from twilio console
client = Client(account_sid, auth_token)
message = client.messages.create(
to="your number",
from_="your twilio number",
body="message body")
print(message.sid) #To print sid
谢谢