如何修复这个错误
问题描述:
我使用的是64位的windows7和Python 2.7.11如何修复这个错误
我已经成功安装了twilio但我有与第一行代码的错误
from twilio.rest import Client
# Your Account SID from twilio.com/console
account_sid = "AC3902a3c28c6cf74a72a464c9062f6979"
# Your Auth Token from twilio.com/console
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)
message = client.messages.create(
to="+15558675309",
from_="+15017250604",
body="Hello from Python!")
print(message.sid)
这里是错误我得到:
Traceback (most recent call last):
File "D:\python\sendText.py", line 1, in <module>
from twilio.rest import Client
ImportError: cannot import name Client
答
在看源文件twilio-6.3 dev0
。你会来看看,有twilio.rest
下__init__.py
暴露没有Client
类,内容如下:
_hush_pyflakes = [set_twilio_proxy, TwilioRestClient,
TwilioConversationsClient, TwilioIpMessagingClient,
TwilioLookupsClient, TwilioPricingClient,
TwilioTaskRouterClient, TwilioTrunkingClient]
正如你可以在上面看到的,而不是Client
,正在使用TwilioRestClient
。
因此,对于你的情况,你需要使用TwilioRestClient
为您的代码工作如下:
from twilio.rest import TwilioRestClient
client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
+0
我刚才这样做之前,我得到你的答案!非常奇怪的是,我从twilio的官方文档中获得了这行代码。任何如何谢谢很多) – Rimond
答
Twilio开发商在这里传道。
twilio-6.3 dev0 tag on GitHub自2016年1月以来未更新。我不知道它在做什么,并会尝试从负责的团队中查找。我建议您使用最新版本的Twilio python helper which is currently 6.1.2。然后,您的原始代码(您称为from twilio.rest import Client
)将可以工作。
您是使用IDE还是命令行?因为相同的代码在pyCharm中工作得很好。 – DineshKumar
请提一下'twilio version' – JkShaw
你的Python shebang在哪里,可以考虑使用一个(甚至在Windows上);也检查权限。 –