python - 导入错误 : cannot import name TwilioRestClient

标签 python twilio

我使用 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(你应该使用它,因为它是最新的)确保你在文档中选择了最新版本。请参阅下图了解如何选择它。

You can change the SDK version at the top right of a code sample, make sure you have 6.x selected.

关于python - 导入错误 : cannot import name TwilioRestClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41013556/

相关文章:

python - 游戏。如何调整表面大小并使所有对象与新窗口大小成比例?

python - 我使用 python3.5 和 OpenCV 3.1.0,OpenCV 函数 cv2.countNonZero(img) 我得到一个错误

javascript - Twilio 任务路由器 : change worker activity when disconnected

python - 使用 Postgres COPY 命令的多对多关系

python - 某些系统上出现奇怪的 urllib2 故障

python - SyntaxError : multiple statements found in python. 有人有这方面的经验吗?

ios - 从“TCHMessageType”强制转换为无关类型“String”总是失败

twilio - 测试 Twilio 的电话号码

reactjs - 创建客户端时无法连接到 twilsock

asp.net - 带有 Visual Studio 2017 和 IIS Express 的 ngrok 无法连接