for key, value in list(result_array.items()):
    insert_array.append('%s = %%s' % key)
data.append(value)
insert_values = ' , '.join(insert_array)
query_insert = 'INSERT into `%s` SET %s ON DUPLICATE KEY UPDATE %s' % (
    insert_table, insert_values, insert_values)
cursor.execute(query_insert, data * 2)
How to Mysql escape in PYTHON