Asterisk AGI Python脚本完成,返回0

时间:2017-08-20 12:41:53

标签: python asterisk raspberry-pi3 agi

我使用在线教程使用AGI在星号中运行Python脚本。但它回来了,

AGI Script easy.py completed, returning 0

所以我启用了调试模式并获得了输出。

启用AGI调试

== Using SIP RTP TOS bits 184  
== Using SIP RTP CoS mark 5    
-- Executing [0112617769@from-trunk:1] Answer("SIP/OBITRUNK1-0000000b", "") 
in new stack  
-- Executing [0112617769@from-trunk:2] AGI("SIP/OBITRUNK1-0000000b", "easy.py") in new stack    
-- Launched AGI Script /var/lib/asterisk/agi-bin/easy.py
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_request: easy.py
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_channel: SIP/OBITRUNK1-0000000b
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_language: en
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_type: SIP
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_uniqueid: 1503228907.11
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_version: 13.15.0
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_callerid: 0713029474
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_calleridname: unknown
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_callingpres: 0 
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_callingani2: 0
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_callington: 0
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_callingtns: 0
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_dnid: 0112617769
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_rdnis: unknown
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_context: from-trunk
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_extension: 0112617769
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_priority: 2
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_enhanced: 0.0
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_accountcode: 
<SIP/OBITRUNK1-0000000b>AGI Tx >> agi_threadid: 1956721696
<SIP/OBITRUNK1-0000000b>AGI Tx >>    
-- <SIP/OBITRUNK1-0000000b>AGI Script easy.py completed, returning 0    
-- Auto fallthrough, channel 'SIP/OBITRUNK1-0000000b' status is 'UNKNOWN'   
-- Executing [h@from-trunk:1] Answer("SIP/OBITRUNK1-0000000b", "") in new stack  
== Spawn extension (from-trunk, h, 1) exited non-zero on 'SIP/OBITRUNK1-0000000b'  
== Using SIP RTP TOS bits 184 
== Using SIP RTP CoS mark 5    
-- Executing [0112617769@from-trunk:1] Answer("SIP/OBITRUNK1-0000000c", "") 
in new stack   
-- Executing [0112617769@from-trunk:2] AGI("SIP/OBITRUNK1-0000000c", "easy.py") in new stack    
-- Launched AGI Script /var/lib/asterisk/agi-bin/easy.py
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_request: easy.py
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_channel: SIP/OBITRUNK1-0000000c
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_language: en
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_type: SIP
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_uniqueid: 1503228913.12
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_version: 13.15.0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_callerid: OBITRUNK1
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_calleridname: unknown
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_callingpres: 0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_callingani2: 0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_callington: 0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_callingtns: 0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_dnid: 0112617769
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_rdnis: unknown
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_context: from-trunk
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_extension: 0112617769
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_priority: 2
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_enhanced: 0.0
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_accountcode: 
<SIP/OBITRUNK1-0000000c>AGI Tx >> agi_threadid: 1980019744
<SIP/OBITRUNK1-0000000c>AGI Tx >>     
-- <SIP/OBITRUNK1-0000000c>AGI Script easy.py completed, returning 0  
-- Auto fallthrough, channel 'SIP/OBITRUNK1-0000000c' status is 'UNKNOWN'    

-- Executing [h@from-trunk:1] Answer("SIP/OBITRUNK1-0000000c", "") in new stack
== Spawn extension (from-trunk, h, 1) exited non-zero on 'SIP/OBITRUNK1-0000000c'  
== Using SIP RTP TOS bits 184

以上代码是我收到电话时得到的。我还想解决三个问题。

问题

1)显示

AGI Script easy.py completed, returning 0

我不知道为什么。作为一个在线论坛建议,我甚至将easy.py位置更改为/var/test/easy.py,但它不起作用。所以我想解决这个问题,因为它没有达到我的期望。

这是easy.py代码。

#!/usr/bin/env python
import sys
from asterisk.agi import *

agi = AGI()
agi.verbose("python agi started")
callerId = agi.env['agi_callerid']
agi.verbose("call from %s" % callerId)
while True:
  agi.stream_file('vm-extension')
  result = agi.wait_for_digit(-1)
  agi.verbose("got digit %s" % result)
  if result.isdigit():
    agi.say_number(result)
  else:
   agi.verbose("bye!")
   agi.hangup()
   sys.exit()

2)当手机响铃时,你可以看到easy.py已经执行了两次。 (这只显示两次但是当它一直响铃时它会在一个循环中执行)。我无法找到解决方案。同样来自第二个循环,它开始将callerid显示为OBITRUNK1。

3)当这段代码运行时,我的固定电话停止振铃,但是当我从extensions.conf文件中删除代码并放置标准的extensions.conf代码时,固定电话会像往常一样振铃。

注意:我知道这是错的。但是由于添加extensions_custom.conf的扩展功能不起作用,我修改了extensions.conf文件。实际上下面是在AGI工作时extensions.conf文件的外观。

的extensions.conf

from trunk:
[from-trunk]
exten => _X.,1,Answer()
exten => _X.,n,AGI(/var/test/easy.py)

希望有人可以帮助我。我试图在几个网站和书籍中找到它们的解决方案,但没有运气。谢谢。

1 个答案:

答案 0 :(得分:1)

这很可能意味着您的脚本中存在错误(语法或其他)。

请注意,调试在SO上是非常有用的。

对于调试脚本,请先停止星号

asterisk -rx "core stop now"

之后在你的控制台中启动它

asterisk -vvvvgc

并致电