如果你希望你的原创总是成功,你可能想使用它。
我有extensions.conf
作为:
[users]
exten=>111,1,Dial(SIP/demo-alice,5)
exten=>111,n,UserEvent(TestResult,result:pass)
exten=>222,1,Dial(SIP/demo-bob,5)
成功了,电话可以互相拨号了。在python测试中:
df = ami.originate(
channel = "Local/222@users",
exten = "111",
priority = "1",
context = "users")
当启动测试时,它失败并给我一个警告:
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'}
通过CLI生成:
channel originate Local/222@users extension 111@users
222振铃,111接听后振铃。
<标题> 更新弄清楚如何在ami.originate()
中发送SIP头。在这里找到。坏的事情是它不工作-发起失败,就像上面记录的错误一样。在dialplan中发送报头也不是一个解决方案。任何帮助吗?
df = ami.originate(
channel = "Local/222@users",
exten = "111",
priority = "1",
context = "users",
variable = {
"SIPAddHeader":"Call-Info: answer-after=0"
})
标题>除非通道双方都应答,否则发起AMI操作失败。你有几个选择。您可以确保每个人都回答,或者您可以处理原始故障(尽管您可能应该这样做,以避免扭曲异常传播):
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)
注意TestCase类为将自动失败并停止测试的初始失败提供了一个默认处理程序(handleoriginatfailure)。