Error in inserting python variable in mysql table
Question: I am working on a raspberry pi project, in which I'm fetching data from plc
and storing it into mysql database.

Here is my code:

    
    
    import minimalmodbus
    import serial
    import mysql.connector
    
    
    instrument = minimalmodbus.Instrument('/dev/ttyAMA0',3,mode='rtu')
    instrument.serial.baudrate=115200
    instrument.serial.parity = serial.PARITY_NONE
    instrument.serial.bytesize = 8
    instrument.serial.stopbits = 1
    instrument.serial.timeout = 0.05
    
    
    con = mysql.connector.connect(user='root',password='raspberry',host='localhost',
                                  database='Fujiplc')
    
    cursor = con.cursor()
    
    try:
        reg_value=instrument.read_register(102)
        print reg_value
        cursor.execute("insert into Register_Values values(%s)",(reg_value))
        print ('One row inserted successfully.')
    except IOError:
        print("Failed to read from PLC.")
    
    
    print (cursor.rowcount)
    
    con.commit()
    
    cursor.close()
    
    con.close()
    

After running this code, I get next error:

    
    
    Traceback (most recent call last):
      File "/home/pi/rpi_to_plc_read.py", line 22, in <module>
        cursor.execute("insert into Register_Values values(%d)",(reg_value))
      File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 477, in execute
        stmt = operation % self._process_params(params)
      File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 355, in _process_params
        "Failed processing format-parameters; %s" % err)
    ProgrammingError: Failed processing format-parameters; argument 2 to map() must support iteration
    

I have gone through so many solutions but problem couldn't solve. Please help
me.


Answer: i think should be.

    
    
    cursor.execute("insert into Register_Values values(%s)",(reg_value))
    con.commit()
    

