twilio-python icon indicating copy to clipboard operation
twilio-python copied to clipboard

Just updated to twilio 6.0.0 and No module named 'twilio.util'

Open sktzofrenic opened this issue 9 years ago • 9 comments

Note: These issues are for bugs and feature requests for the helper libraries. If you need help or support, please email [email protected] and one of our experts will assist you!

Version:6.0.0 Browser Softphone Capability Token:

Code Snippet

from twilio.util import TwilioCapability  # This used to work

Exception / Log

  File "app.py", line 5, in <module>
    from twilio.util import TwilioCapability
ImportError: No module named 'twilio.util'


Steps to Reproduce

  1. Try to import and it fails.

sktzofrenic avatar Apr 03 '17 23:04 sktzofrenic

The reason I upgraded was to get the new fax functionality, but it does not appear to be in the new library update. Please let me know if I'm missing it.

sktzofrenic avatar Apr 03 '17 23:04 sktzofrenic

@sktzofrenic Thanks for writing in!

  1. TwilioCapbility has been moved here: https://github.com/twilio/twilio-python/blob/master/twilio/jwt/client/init.py

  2. Fax features exist in the alpha line of the library as it is still a beta product: https://github.com/twilio/twilio-python/blob/alpha/twilio/rest/fax/init.py The latest version there is 6.0.0a1.

jingming avatar Apr 03 '17 23:04 jingming

Alright that solved that one, now where did you move this module?

from twilio.rest import TwilioRestClient # also prodcues error

Or has that been renamed Client and located here: https://github.com/twilio/twilio-python/blob/master/twilio/rest/init.py

?

If so, how do I initialize it since it no longer can be initialized with account_sid and auth_token. Instead it wants a username and password?

EDIT: I see now from reviewing the code that username and password are the same thing as sid and token.

sktzofrenic avatar Apr 03 '17 23:04 sktzofrenic

yes, username and password can be account_sid and auth_token. They were renamed because account_sid and auth_token is not the only method you can use to auth.

jingming avatar Apr 04 '17 00:04 jingming

Unfortunately, the whole thing crashed my app. Too many breaking changes and not enough documentation. I don't think the twilio JS client is setup for the new changes. Even the public beta version could not recognize the capability tokens generated by the new python ClientCapabilityToken generator. So since none of my clients could authenticate it's basically unusable in the current state.

I am looking forward to these updates though.

Just as an example, the previous token generator made something that looked like this:

{
  "identity": "jrussel", 
  "token": "eyJ0eXAiOiAiSldUIiwgImFsZyI6ICJIUzI1NiJ9.eyJleHAiOiAxNDkxMzA5MTAzLCAiaXNzIjogIkFDMWE1YWJjMDlkNWY5Yjc4YzY5ZjRiYzRhMjdiZTI3NzkiLCAic2NvcGUiOiAic2NvcGU6Y2xpZW50Om91dGdvaW5nP2FwcFNpZD1BUGY1NTNhYTkxZjg4NzQ3YzRkZTJiNTI0MzFiZGJlOTBmJmNsaWVudE5hbWU9anJ1c3NlbCBzY29wZTpjbGllbnQ6aW5jb21pbmc_Y2xpZW50TmFtZT1qcnVzc2VsIn0.BfikbegvxZVswRsIz-xZscsCODwxAawjdIBbsDd9HHI"
}

Whereas the new generator doesn't seem to encode properly when I call the new _generate_token() method

{
  "identity": "izabella05", 
  "token": {
    "scope": "scope:client:incoming?clientName=izabella05 scope:client:outgoing?appSid=APxxxxxxxxxxxxxxxxxxxxxx&clientName=izabella05"
  }
}

sktzofrenic avatar Apr 04 '17 00:04 sktzofrenic

@sktzofrenic you shouldnt be calling the _generate_token method, you should call to_jwt i believe.

codejudas avatar Apr 05 '17 23:04 codejudas

For anyone else having issues migrating to the new version, we have a guide to update your app to the new 6.x library: https://www.twilio.com/docs/libraries/python/migration-guide

codejudas avatar May 08 '17 17:05 codejudas

@efossier just a note that the migration guide doesn't specify anything about the util / TwilioCapability breaking change

anotherstarburst avatar May 27 '17 17:05 anotherstarburst

For anyone reading this, it looks like this page details the usage of the new class https://www.twilio.com/docs/guides/client/capability-tokens - from what I can see you import and use

from twilio.jwt.client import ClientCapabilityToken

In the same way as TwilioCapability

anotherstarburst avatar May 27 '17 17:05 anotherstarburst