python2中mysql插入中文的问题
insert_sql_template = """
insert into ap_console_template (`id`, `name`, `type`, `content`, `desc`) values (%s, '%s', %s, '%s', '%s')
"""
for row_data in all_data:
new_row = []
for i in row_data:
print(i, type(i))
if isinstance(i, unicode):
i = i.encode("utf-8")
new_row.append(i)
insert_sql = insert_sql_template % tuple(new_row)
cur.execute(insert_sql)