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

twilio.TwilioRestException - Docs bug, or import problem?

Open foxx opened this issue 12 years ago • 15 comments

The docs say that TwilioRestException can be accessed from twilio.TwilioRestException, but this is not the case.

You instead need to use twilio.rest.exceptions.TwilioRestException.

Is this a documentation bug, or should twilio.TwilioRestException actually work?

foxx avatar Sep 13 '14 14:09 foxx

This problem was introduced in 4a2f191c9d697a9198158e38675e4b01c4aa430d, which moved the class. I agree that this is a breaking change, because the documented API and implementations prior to 3.6.7 offered that class in twilio.TwilioRestException. It needs to be reimported into the appropriate namespace.

tdierks avatar Sep 17 '14 17:09 tdierks

The exceptions should still be importable like so:

from twilio import TwilioRestException

and also like so:

from twilio.rest.exceptions import TwilioRestException

This should prevent any backwards compatibility issues. I have no problems with version 3.6.7, which version are you on?

phalt avatar Sep 29 '14 14:09 phalt

Sure, you can change your code to be compatible with the change and still work with old binaries, and I've done so, but that doesn't change the fact that this change and minor release broke code which relied on the documented API, and will presumably continue to break developers as they update. What's the problem with importing the exception into the spot in the namespace that it's documented to live?

Edit: sorry, I wasn't thinking (still drinking coffee), and misremembered the problem as being with twilio.rest.TwilioRestException. @foxx is right; the problem is that twilio.TwilioRestException doesn't work.

tdierks avatar Sep 29 '14 14:09 tdierks

@phalt That's the point, the exception is currently not importable using;

from twilio import TwilioRestException

You are right that it should be working, but it isn't (as per latest release from 16 days ago).

foxx avatar Sep 29 '14 14:09 foxx

@tdierks I think the issue here is I changed how we separated the exceptions and I missed this in the documentation. I'm looking into fixing the backwards compatible namespace issue now.

@foxx - can you run pip freeze and see what version you have? I'm on 3.6.7 and I have no issues.

phalt avatar Sep 29 '14 14:09 phalt

Sorry this took me so long, I was stuck in my own personal logic loop (in my head) seeing code that I thought was running, when I was actually running an installed version and not my local, new, code.

phalt avatar Sep 29 '14 14:09 phalt

Here you go;

$ pip freeze | grep twilio
twilio==3.6.7
>>> from twilio import TwilioRestException
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name TwilioRestException

>>> twilio.__version_info__
('3', '6', '7')

foxx avatar Sep 29 '14 15:09 foxx

Thanks @foxx - I think I found the issue.

phalt avatar Sep 29 '14 15:09 phalt

@phalt Could you ref the commit which fixes this?

foxx avatar Oct 13 '14 18:10 foxx

Sure. Fixed with 7df5a01e51335cf6c7aaf3023b1832e8ffccb425

phalt avatar Oct 13 '14 18:10 phalt

In case anyone (like me) came here trying to figure out where to import from, it's now from twilio.base.exceptions import TwilioRestException (as of 64fc4e01e8197acd521792e770baeeb99eebfa3b).

gregjkal avatar May 14 '18 21:05 gregjkal

can we update the docs located here? https://twilio-python.readthedocs.io/en/latest/api/rest/ I would do it but I can't seem to find the file associated with it.

robechun avatar Dec 20 '18 02:12 robechun

Hey @Altrum - thanks for letting us know. The docs on Read the Docs were definitely out of date, I just pulled them down.

The best place for docs and sample code on using this library live on www.twilio.com/docs. We have lots of automation and testing in place on those docs to make sure they're always up to date.

Let me know if you can't find what you're looking for there and I can try to help.

atbaker avatar Dec 20 '18 03:12 atbaker

TwilioRestException: Unable to create record: Permission to send an SMS has not been enabled for the region indicated by the 'To' number:______________

i am using twilio first time for sms and its showing this error .can anyone help me to solve this problem.

mahimakaushik-oss avatar Oct 25 '20 17:10 mahimakaushik-oss

@mahimakaushik-oss Please open a new issue.

childish-sambino avatar Oct 26 '20 14:10 childish-sambino