[asterisk-users] No joy with my first AGI Python script

D'Arcy J.M. Cain darcy at Vex.Net
Wed Jan 6 11:19:19 CST 2016

It's very simple but it doesn't work.  Here's the entire script.

#! /usr/bin/python

import sys

env = {}

def comm(cmd):
    sys.stdout.write(cmd.strip() + '\n')
    return sys.stdin.readline().strip()

while 1:
   line = sys.stdin.readline().strip()

   if line == '': break

   key,data = line.split(':')
   if key[:4] == 'agi_':
       key = key.strip()[4:]
       data = data.strip()
       if key: env[key] = data

#comm("Verbose(0,pyast: %s)" % sys.argv)
comm('SAY NUMBER 123 ""')

sys.stderr.write("AGI Environment Dump:\n");
for key in env.keys():
   sys.stderr.write(" -- %s = %s\n" % (key, env[key]))


The extension is;

exten => *22,1,Verbose(0,${CHANNEL(peername)} calling 22 TEST)
  same => n,AGI(/home/darcy/pyast,Hello world)
  same => n,Hangup

What happens when I dial it is that the dialplan Verbose statement runs
but nothing else is logged and the number is not said.  When I turn on
AGI debugging I get this:

... (a bunch of agi_ variables)
<SIP/darcy-0000000d>AGI Tx >> agi_arg_1: Hello world
<SIP/darcy-0000000d>AGI Tx >> 
<SIP/darcy-0000000d>AGI Rx << SAY NUMBER 123 ""
<SIP/darcy-0000000d>AGI Tx >> 200 result=0

There is a delay between the last Rx and Tx suggesting that it thinks
that the numbers are being played but I don't hear them.  Also, the
output to stderr does not appear in the logs.

Here is my environment:
 - Asterisk 11.20.0
 - NetBSD 7.0
 - Python 3.4

Thanks in advance for any help or suggestions.

D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:darcy at Vex.Net
VoIP: sip:darcy at Vex.Net

More information about the asterisk-users mailing list