Sqlite format string
Tim Chase
python.list at tim.thechases.com
Sat Aug 29 17:12:06 EDT 2009
> I have this statement cursor.execute("SELECT * from session_attribute WHERE
> sid=%s", ( user ))
> and I'm receiving this error :
>
> TypeError: not all arguments converted during string formatting
Two possibilities occur to me:
1) the 2nd parameter to execute() usually needs to be a tuple (or
maybe a list), so try
cursor.execute("select ...", (user, ))
with the extra comma after "user".
2) More likely, check your sqlite3.paramstyle to see what sqlite
is expecting (it's defined at the module-level):
import sqlite3
print sqlite3.paramstyle
Mine here is set to "qmark" which means that sqlite is expecting
cursor.execute("... WHERE sid=?", (user,))
instead of the "format" style you're using:
cursor.execute("... WHERE sid=%s", (user,))
as defined in http://www.python.org/dev/peps/pep-0249/
Hope this helps,
-tkc
More information about the Python-list
mailing list