I'm getting the exception _mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
when calling this function to insert a student. The number of parameters in the query matches the number of arguments I'm passing though. My other SQL queries work fine. I am using Flask-MySQLdb on Python 3 to handle the MySQL connection.
def create_student(surname, forename, dob, address, phone, gender, tutor, email):
cursor = mysql.connection.cursor()
cursor.execute('''
INSERT INTO students(surname, forename, dob, address, phone, gender, tutor, email)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)''', (surname, forename, dob, address, phone, gender, tutor, email))
mysql.connection.commit()
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/mnt/c/Users/root/Desktop/student-admin/main.py", line 184, in create
if create_student(surname, forename, dob, address, phone, gender, tutor, email):
File "/mnt/c/Users/root/Desktop/student-admin/main.py", line 60, in create_student
VALUES(?, ?, ?, ?, ?, ?, ?, ?)''', (surname, forename, dob, address, phone, gender, tutor, email))
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 240, in execute
self.errorhandler(self, ProgrammingError, str(m))
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 52, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: not all arguments converted during string formatting