AGI with Python problem

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]#!/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()[/code]

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?

I have the exact same issue using sqlite. I thought it had something to do with the right of asterisk being able to query the db, even after changing the right still get the same.

I’m not catching any error when trying to connect. It just return None…

clueless:|

The original question relates to accessing SQLite and the involvement of Asterisk is not relevant to the problem. If you have exactly the same issue, you need an SQLite or forum, or one for the MySQLdb class library.

I think I misunderstood the question then. my apologies.