DB_CURSOR.execute("""INSERT INTO %s
(name,created_by,state,description,docs,admin_email,date_created)
VALUES(%%s,%%s,%%s,%%s,%%s,%%s,%%s)""" % hosts_table,
(hostname, created_by, state, description, docroot, admin_email, date_created))
Note that the hosts_table variable is a single % sign, and all the other variables are two %% so they are ignored in the initial Python string interpolation, then change to a single % for the mysqldb part.
Try this in the Python prompt to see what I mean:
>>> '%%s %s' % 'x'
'%s x'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…