14

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)
philnash
  • 70,667
  • 10
  • 60
  • 88
Vivian
  • 209
  • 1
  • 3
  • 8
  • 3
    Please see https://stackoverflow.com/help/how-to-ask if you want help, as this is too broad to help at the moment. You need to write your code, and provide a full error message. – A. N. Other Dec 07 '16 at 09:26
  • What is the problem you are talking about? – Mixone Dec 07 '16 at 09:42
  • there is a snapshot of my code, i will give another copy of my code here:from twilio.rest import TwilioRestClient; account_sid = "{{ AC6320ef6dd8b9e4e936176b26d1607800 }}" # Your Account SID from www.twilio.com/console auth_token = "{{ 934ac00ae7179bd7d60bb5cd09f89663 }}" # 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) – Vivian Dec 07 '16 at 09:47
  • 1
    and the error that you get? – Mixone Dec 07 '16 at 10:13
  • @Mixone,the title of my question is the error I got, I'm sorry, my English is poor, may not described it clearly, I will improve that. – Vivian Dec 08 '16 at 08:09
  • Do you have a file in your project called twilio.py at all? – philnash Dec 08 '16 at 09:46
  • @philnash Thank you, philnash. May be the twilio version problem, after change it to 5.6.0, there is no error. – Vivian Dec 08 '16 at 09:50
  • @Vivian , my bad! Next time have a title that rather says: Having trouble with... And in question say: The error is....... But my bad this time around – Mixone Dec 08 '16 at 14:24
  • @Mixone,no,no,no,that's my bad, next time I'll improve my questions like you said. Thank you for your advice, that helps me a lot, thank you! – Vivian Dec 09 '16 at 01:46
  • In my case I had accidentally removed `twilio_api`, and it worked when I reinstalled it. – abk Dec 10 '22 at 22:26

3 Answers3

27

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.

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

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 1
    Oh, I see, that's my bad, I didn't download the latest version selected in the docs. Next time I should notice the changes, thank you so much. I will update the vision of twilio to 6.0, see if it will work. – Vivian Dec 09 '16 at 01:52
  • I already try it, if the twilio version is 5.x, the module you should import is "TwilioRestClient"; if the twilio version is 6.x, the mudule you should import is "Client" – Vivian Dec 09 '16 at 02:22
  • Great! Glad this is working for you now. Perhaps we can make the version clearer to avoid this in the future. – philnash Dec 09 '16 at 12:01
  • 1
    You'd think they'd mention that on the front-page where it shows the wrong sample. – Blairg23 Apr 25 '17 at 17:30
  • Which page is that? I'd love to get it fixed! – philnash Apr 25 '17 at 19:04
5

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.

Vivian
  • 209
  • 1
  • 3
  • 8
  • New functionality will only be added to the new library (Python Helper Library 6.x). The old library (5.x) is no longer supported: Twilio will not provide bug fixes and Support might ask you to upgrade before debugging issues.https://www.twilio.com/docs/libraries/python?code-sample=code-python-helper-library-sms-test&code-language=Python&code-sdk-version=default#accessing-the-5x-version-of-the-helper-library – Sandeep Balagopal Mar 18 '19 at 05:49
2

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