First of all, never create raw SQL queries like this. Never. This requires parameterized queries. You are requesting an SQL injection attack.
If you want to store arbitrary data, such as Python dictionaries, you must serialize this data. JSON would be a good choice for the format.
In general, your code should look like this:
import MySQLdb import json db = MySQLdb.connect(...) cursor = db.cursor() dic = {'office': {'component_office': ['Word2010SP0', 'PowerPoint2010SP0']}} sql = "INSERT INTO ep_soft(ip_address, soft_data) VALUES (%s, %s)" cursor.execute(sql, ("192.xxx.xx.xx", json.dumps(dic))) cursor.commit()
vartec
source share