0
0 комментариев

Error: rlm_python:EXCEPT:: (2006, 'MySQL server has gone away')

db = MySQLdb.connect(host="10.0.1.1",user="111",passwd="111",db="111")
cursor = db.cursor()
 
def mac_search(*args):
    serid=[465,641,465,641,638,637,644,645,648,709,1022,1120,1122,1124]
    sql = """SELECT sl2.service_id FROM ip_groups AS ig \
            JOIN iptraffic_service_links AS isl ON ig.ip_group_id=isl.ip_group_id \
            JOIN service_links AS sl ON isl.id=sl.id \
            JOIN accounts AS ac ON sl.account_id=ac.id \
            JOIN service_links AS sl2 ON ac.id=sl2.account_id \
            WHERE ig.mac='%s' \
            AND ig.is_deleted=0 \
            AND isl.is_deleted=0 \
            AND sl.is_deleted=0 \
            AND ac.is_deleted=0 \
            AND sl2.is_deleted=0;""" %args[0].split()[0]
    cursor.execute(sql)
    for j1 in cursor.fetchall():
        if j1[0] in serid:
            cursor.execute("SELECT * FROM s_multicast WHERE service_id=%s AND %s>=ip_start AND %s<=ip_end;" %(j1[0],args[0].split()[1],args[0].split()[1]))
            return cursor.fetchone()
 
def authorize(p):
    mac = "{0}:{1}:{2}:{3}:{4}:{5}".format(p[0][1][1:-1][:2],p[0][1][1:-1][2:4],p[0][1][1:-1][4:6],p[0][1][1:-1][6:8],p[0][1][1:-1][8:10],p[0][1][1:-1][10:12]).lower()
    ipm = "{0}".format(struct.unpack("!I", socket.inet_aton(p[8][1]))[0])
    data = "{0} {1}".format(mac,ipm)
    start = time.time()
    g = mac_search(data)
    print "!!!Elapsed Time: %.4f" %(time.time() - start)
    if g:
        return radiusd.RLM_MODULE_OK
    else:
        accounting(p)
        return radiusd.RLM_MODULE_REJECT
 
def accounting(p):
    if p[8][0] == 'Acct-Status-Type':
        sql = """INSERT INTO s_multicast_log (mac,sw_ip,port,channel,date,status) VALUES ('%s','%s',%d,'%s',UNIX_TIMESTAMP(),'2')""" %(p[0][1][1:-1],p[1][1],int(p[6][1]),p[7][1])
    else:
        sql = """INSERT INTO s_multicast_log (mac,sw_ip,port,channel,date,status) VALUES ('%s','%s',%d,'%s',UNIX_TIMESTAMP(),'0')""" %(p[0][1][1:-1],p[2][1],int(p[7][1]),p[8][1])
    try:
        cursor.execute(sql)
        db.commit()
        return radiusd.RLM_MODULE_OK
    except:
        db.rollback()
        return radiusd.RLM_MODULE_FAIL
 
def post_auth(p):
    return radiusd.RLM_MODULE_NOOP

Из-за чего может быть вызвана данная ошибка?


Добавить комментарий