I am trying to pass multiple Python variables to an SQL query in pymysql but always receive "TypeError: not all arguments converted during string formatting". For debugging purposes, there are no other records in this table:
c.execute('''CREATE TABLE upcoming_events1(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
html_insert TEXT,
date INT(11),
institution VARCHAR(5))''')
header = "test string"
my_html = "some html, also a string"
event_date = "1273627537"
event_institution = "xyz"
c.execute('''INSERT INTO upcoming_events1 (name, html_insert, date, institution) VALUES (%s);''', (header, my_html, event_date, event_institution, ))
c.execute('''SELECT * FROM upcoming_events1''')
debug = c.fetchall()
print(debug)
I have already read as much as I could find on the error in this context. Many posts (cf. here, here, here, and here) suggest that something seems to be wrong with the parameter substitution syntax around %s, but I just can't find the mistake. This also dealt with multiple parameters, but I do not see me actively passing any "None" types. I have tried reducing the number of parameters passed at a time in various combinations and noticed that while two or more variables cannot be passed in one statement, every single one of them individually can. In case this should be relevant: I have foreign keys in other tables referencing the id column, as you can see I do not try to pass any values to it here though (mentioning it because it seemed like the issue might have been caused by constraints here).
You are missing couple of %s
s. Correct statement:
c.execute('''INSERT INTO upcoming_events1 (name, html_insert, date, institution) VALUES (%s, %s, %s, %s);''', (header, my_html, event_date, event_institution, ))