ImportError: cannot import name TwilioRestClient

旧巷老猫 提交于 2019-11-27 07:38:30

问题


I ran the Example code of send text using Twilio,the code from:https://www.twilio.com/docs/libraries/python my code is:

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) 

I already install the twilio,using pip, why this problem happened,please help~ there is a copy of my code:

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)

回答1:


Twilio developer evangelist here.

I know you've answered yourself by changing the version of the library from 6.0 to 5.6.0, but that's what alerted me to the actual problem!

When using the Twilio Python helper library version 6.0, you need to import Client not TwilioRestClient.

I wonder if you had the documentation set to show the 5.6.0 library examples. If you want to use 6.0 (which you should as it is the most up to date) make sure you have the latest version selected in the docs. See the image below for how to select it.




回答2:


I know what's wrong. The version of twilio is 6.0 when the error happend; I try to change the version of twilio, I change it to 5.6.0,there is no error shows.




回答3:


I am using twilio version 6+

When I tried with twiliorestclient even got the same error as mention upper, now I am trying this , this solve my problem even

 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 

Thanks



来源:https://stackoverflow.com/questions/41013556/importerror-cannot-import-name-twiliorestclient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!