Reputation: 328
I have extensions.conf
as:
[users]
exten=>111,1,Dial(SIP/demo-alice,5)
exten=>111,n,UserEvent(TestResult,result:pass)
exten=>222,1,Dial(SIP/demo-bob,5)
It works, phones can dial each other. In python test:
df = ami.originate(
channel = "Local/222@users",
exten = "111",
priority = "1",
context = "users")
While launching the test, it failes and gives me a warning:
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/starpy/manager.py", line 153, in lineReceived
self.dispatchIncoming() # does dispatch and clears cache
File "/usr/lib/python2.7/dist-packages/starpy/manager.py", line 241, in dispatchIncoming
callback(message)
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 362, in callback
self._startRunCallbacks(result)
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 458, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 545, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/usr/lib/python2.7/dist-packages/starpy/manager.py", line 347, in errorUnlessResponse
raise error.AMICommandFailure(message)
starpy.error.AMICommandFailure: {'message': 'Originate failed', 'response': 'Error', 'actionid': 'VirtATS3-36015280-2'}
Originating through CLI works as it should:
channel originate Local/222@users extension 111@users
222 rings, after answering the call 111 begins to ring.
Figured out how that I can send SIP headers in ami.originate()
. Found here. The bad thing that it is not working - originate fails like in a error logged above. Sending headers in dialplan is not a solution either. Any help?
df = ami.originate(
channel = "Local/222@users",
exten = "111",
priority = "1",
context = "users",
variable = {
"SIPAddHeader":"Call-Info: answer-after=0"
})
Upvotes: 1
Views: 1331
Reputation: 2884
An Originate AMI action fails unless both sides of the channel are Answer(ed). You have a few options here. You can either make sure everyone Answers, or you can handle the originate failure (although you should probably do this anyway to avoid the twisted exception from propagating):
def __handle_originate_failure(self, reason):
print "Originate failure: %s" % reason
return reason
df = ami.originate(
channel = "Local/222@users",
exten = "111",
priority = "1",
context = "users")
df.addErrback(__handle_originate_failure)
Note that the TestCase class provides a default handler (handleOriginateFailure) for Originate failures that will automatically fail and stop the test. If you expect that your Originate should always succeed, you may want to use that.
Upvotes: 2