Error When calling stored procedure in python - Using MySQLdb

mysql, mysql-python, python, python-2.7

Solution

You want `cur.callproc('test', (data,))` to pass a tuple of 1 element

eg:

>>> a = 'hello'
>>> len(a) # just a
5
>>> len( (a) ) # still just a
5
>>> len( (a,) ) # single element tuple containing a
1

Problem

I have a MySQL stored procedure called test which accepts one argument. I can execute the stored procedure from python 2.7x using below code ``` data='Teststr' cur = db.cursor() cur.execute("CALL test('{0}')".format(data)) ``` But when I use ``` data='Teststr' cur = db.cursor() cur.callproc('test',data) ``` I am encountering `OperationalError: (1318, 'Incorrect number of arguments for PROCEDURE MyDb.test; expected 1, got 7')` Looks like python treats each character as one argument. What am I missing here?

Original source