AttributeError: 'tuple' object has no attribute 'encode'

Paul Boddie paul at
Thu Apr 5 18:37:44 CEST 2007

erikcw wrote:
> I'm trying to build a SQL string
> sql = """INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d)""",
> (cid, ag,[parent][child]['results']['test'])

This makes a tuple, though: the first element is the SQL string; the
second element contains a tuple of parameters.

> It raises this error: AttributeError: 'tuple' object has no attribute
> 'encode'

What does? I imagine that this error comes from a call to a cursor
object's execute method. In other words, I imagine that you may be
doing something like this:


Not that there would be anything obviously wrong with that: you are
keeping the string and its parameters separate, after all. However,
you'd have to show us the full error (a traceback including lines of
code from the database library) for us to really see what's going on.

> Some of the variables are unicode (test and ag) - is that what is
> causing this error?  What do I need to do to make it work?

Show us more of the error! ;-)


More information about the Python-list mailing list