在python中调用存储过程时出错-使用MySQLdb

在python中调用存储过程时出错-使用MySQLdb,python,mysql,python-2.7,mysql-python,Python,Mysql,Python 2.7,Mysql Python,我有一个名为test的MySQL存储过程,它接受一个参数。 我可以使用下面的代码从Python2.7x执行存储过程 data='Teststr' cur = db.cursor() cur.execute("CALL test('{0}')".format(data)) 但是当我使用 data='Teststr' cur = db.cursor() cur.callproc('test',data) 我遇到 OperationalError:(1318,'程序MyDb.test的参数数量不正

我有一个名为test的MySQL存储过程,它接受一个参数。 我可以使用下面的代码从Python2.7x执行存储过程

data='Teststr'
cur = db.cursor()
cur.execute("CALL test('{0}')".format(data))
但是当我使用

data='Teststr'
cur = db.cursor()
cur.callproc('test',data)
我遇到

OperationalError:(1318,'程序MyDb.test的参数数量不正确;应为1,得到7')


看起来python将每个字符视为一个参数。我在这里遗漏了什么?

您想要
cur.callproc('test',(data,)
传递一个由1个元素组成的元组

例如:


+这很有效,非常感谢。我在这上面浪费了一个小时:)。
>>> a = 'hello'
>>> len(a) # just a
5
>>> len( (a) ) # still just a
5
>>> len( (a,) ) # single element tuple containing a
1