 <p>You are not passing any parameters to the query.</p> <p>Instead of:</p> <pre><code>cur.execute('INSERT INTO report_table (id, date, time, status) VALUES (id, date, time, status)') </code></pre> <p>create a parameterized query:</p> <pre><code>cur.execute("""INSERT INTO report_table (id, date, time, status) VALUES (%(id)s, %(date)s, %(time)s, %(status)s)""", {'id': id, 'date': date, 'time': time, 'status': status}) </code></pre> <p>There are other fixes you should apply to the code:</p> <ul> <li>define <code>db</code> and <code>cursor</code> variables before the loop so that you don't need to connect to the database and open a cursor on every iteration</li> <li>you should properly close the cursor and connection objects</li> <li>instead of calling <code>INSERT</code> database query on each iteration step, consider gathering the data into a list and then insert once after the loop</li> </ul> <p>Hope that helps.</p>