I'm trying to insert a python variable into a MySQL table within a python script but it is not working. Here is my code
add_results=("INSERT INTO account_cancel_predictions"
"(account_id,21_day_probability,flagged)"
"Values(%(account_id)s,%(21_day_probability)s,%(flagged)s)")
data_result={
'account_id':result[1,0],
'21_day_probability':result[1,1],
'flagged':result[1,2]
}
cursor.execute(add_results,data_result)
cnx.commit()
cursor.close()
cnx.close()
This gets the error
ProgrammingError: Failed processing pyformat-parameters; 'MySQLConverter' object has no attribute '_float64_to_mysql'
However, when I replace the variable names result[1,0]
, result[1,1]
, and result[1,2]
with their actual numerical values it does work. I suspect python is passing the actual variable names rather than the values they hold. How do I fix this?