1

我有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开始响铃。

更新

弄清楚我如何发送 SIP 标头ami.originate()在这里找到。它不起作用的坏事 - 起源失败,就像上面记录的错误一样。在拨号方案中发送标头也不是解决方案。有什么帮助吗?

    df = ami.originate(
        channel = "Local/222@users",
        exten = "111",
        priority = "1",
        context = "users",
        variable = {
            "SIPAddHeader":"Call-Info: answer-after=0"
            })
4

1 回答 1

2

除非通道的两边都是 Answer(ed),否则 Originate 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 类为 Originate 失败提供了一个默认处理程序 (handleOriginateFailure),它将自动失败并停止测试。如果您希望您的 Originate 应该总是成功,您可能想要使用它。

于 2013-05-29T14:36:14.817 回答