我使用 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)
最佳答案
此处为 Twilio 开发人员布道师。
我知道您已经通过将库的版本从 6.0 更改为 5.6.0 来回答自己,但这才是提醒我注意实际问题的原因!
使用 Twilio Python helper library 时版本 6.0,您需要导入 Client
而不是 TwilioRestClient
。
我想知道您是否设置了文档来显示 5.6.0 库示例。如果你想使用 6.0(你应该使用它,因为它是最新的)确保你在文档中选择了最新版本。请参阅下图了解如何选择它。
关于python - 导入错误 : cannot import name TwilioRestClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41013556/