Python Forum

Full Version: mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone. Im a newbie in python.
I have the code below. Im on ubuntu 18.04. the variable "output " is a json data in my code.

import wmi_client_wrapper as wmi
import mysql.connector
from mysql.connector.constants import ClientFlag
from datetime import datetime
import json

exec(open("/etc/epp/SNMP/mysqlconnector.py").read())

wmi = wmi.WmiClientWrapper(
username="Administrator",
password="Ares4382)",
host="192.168.1.240",
)

output = wmi.query("SELECT * FROM Win32_Processor")
#print(output)
#y = json.dumps(output)
#print(y)

for item in output:

 sql = "INSERT INTO wmi_inventory (wmi_data) VALUES (%s, %s)"
 now = datetime.now()
 dt_string = now.strftime("%Y-%m-%d-%H:%M:%S")
 val = (output, dt_string)
 cursor.execute(sql, val)
 connection.commit()
 
When i execute my code it gives me error
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'list' cannot be converted to a MySQL type


How can i solve this error?
Sorry for my bad question asking.
I edited it. I already post my all code and error :(
Did you mean to put the item that is currently being iterated over from output and not output itself in the following line.
val = (output, dt_string)
I want to insert this line into my db.
So i want to insert the output

output = wmi.query("SELECT * FROM Win32_Processor")