AGI with Python problem

Get help with installing, upgrading and running Asterisk.

Moderators: muppetmaster, Moderator, Support

AGI with Python problem

Postby okywan » Tue May 08, 2012 6:58 am

Hello,

I need my asterisk to write to a DB the caller ID and the callee ID so I can monitor on real time.

I've done a python script that looks like this:

Code: Select all
#!/usr/bin/env python

from asterisk import agi
import asterisk
import sys
import MySQLdb
import os
import datetime


env = {}

while 1:
    line = sys.stdin.readline( ).strip( )
    if line == '':
        break
   key,data=linea.split(':')
   key=key.strip()
   data=data.strip()
   if key<>'':
      env[key]=data

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

#numeroA=env['agi_callerid']
#numeroB=asterisk.agi.get_variable(agi_extension)

numeroA=666
numeroB=999

try:
   db=MySQLdb.connect(host='localhost',user='myuser'',passwd='mypass')
   cursor=db.cursor()
   #cursor.execute("INSERT INTO `informer`.`LlamadasActivas` (Llamante, Llamado) VALUES (%s, %s)",(env['agi_callerid'],env['agi_extension']))
   cursor.execute("INSERT INTO `informer`.`LlamadasActivas` (Llamante, Llamado) VALUES (%s, %s)" %(numeroA, numeroB))
   
except MySQLdb.Error, e:
   print "Error en la conexion mysql %d: %s" % (e.args[0],e.args[1])
   
finally:
   if db:
      db.close()


The thing is that I'm not getting any results on the DB, nor any message into the console even when I'm looping and printing the info received from Asterisk at the initial AGI call.

The console in Asterisk shows the script is being called, and returns 0 as a result which makes me think it doesn't pop errors however no info is being added to the DB.

Any tips?
okywan
Newsterisk
 
Posts: 3
Joined: Thu Oct 27, 2011 4:12 pm

Return to Asterisk Support

Who is online

Users browsing this forum: Lexus45 and 16 guests