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

<p>Here is my code:</p>

<pre><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()
</code></pre>

<p>After running this code, I get next error:</p>

<pre><code>Traceback (most recent call last):
  File "/home/pi/rpi_to_plc_read.py", line 22, in &lt;module&gt;
    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
</code></pre>

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

<p>i think should be.</p>

<pre><code>cursor.execute("insert into Register_Values values(%s)",(reg_value))
con.commit()
</code></pre>

python mysql raspberry-pi