2

im using twilio-python and im following this tutorial: http://readthedocs.org/docs/twilio-python/en/latest/usage/twiml.html?highlight=nest

But when i try this:

from twilio import twiml

r = twiml.Response()
r.say("hello")
with r.gather(finishOnKey=4) as g:
    g.say("world")
print str(r)

But i get this:

AttributeError: __exit__

Any idea?

2 Answers 2

2

It seems they aren't really compatible with the with statement. Try this:

from twilio import twiml

r = twiml.Response()
r.say("hello")
g = r.gather(finishOnKey=4)
g.say("world")
print str(r)

Here's what I get:

>>> from twilio import twiml
>>> 
>>> r = twiml.Response()
>>> r.say("hello")
<twilio.twiml.Say object at 0x1098d05d0>
>>> g = r.gather(finishOnKey=4)
>>> g.say("world")
<twilio.twiml.Say object at 0x1098d0950>
>>> print str(r)
<?xml version="1.0" encoding="UTF-8"?><Response><Say>hello</Say><Gather finishOnKey="4"><Say>world</Say></Gather></Response>
Sign up to request clarification or add additional context in comments.

1 Comment

Please see Rob's answer below detailing their fix.
2

Emmet - good catch.

Matt - pitch perfect response.

We've just pushed a fix for this issue with 3.3.2 - you can pick it up off PyPi or at the GitHub repo here:

https://github.com/twilio/twilio-python

Just update your module and the documented approach will work. Please shoot an email to the address in my profile - you guys just earned a Twilio T-shirt. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.