The issue here is not your MySQL code but it is this try/except block:
try:
cursor.execute("INSERT INTO radcheck(username, attribute, op, value) VALUES(%s, 'Password', ':=', %s)", (username, password))
conn.commit()
print 'OK user '+ username +' successfully added with hash'+ password
sys.exit(0)
except:
conn.rollback()
print 'FEHLER query failed'
sys.exit(1)
When you call sys.exit(0)
, it raises an exception called SystemExit
. Since a bare except:
catch statement catches SystemExit
, this block will always be executed when you call sys.exit(0)
. To prevent this from happening, change your except:
catch to:
except Exception as e:
conn.rollback()
print 'FEHLER query failed'
sys.exit(1)
Even better is if you catch only MySQL errors with:
except MySQLdb.Error as e:
conn.rollback()
print 'FEHLER query failed'
sys.exit(1)