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

erikcw erikwickstrom at gmail.com
Thu Apr 5 12:01:14 EDT 2007


On Apr 5, 11:41 am, kyoso... at gmail.com wrote:
> On Apr 5, 10:31 am, "erikcw" <erikwickst... at gmail.com> wrote:
>
> > Hi,
>
> > I'm trying to build a SQL string
>
> > sql = """INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d)""",
> > (cid, ag, self.data[parent][child]['results']['test'])
>
> > It raises this error: AttributeError: 'tuple' object has no attribute
> > 'encode'
>
> > 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?
>
> > Thanks!
> > Erik
>
> It sounds like you're not calling the "encode" method correctly. But
> it's hard to say when you didn't include that bit of code. You may
> need to check your database's docs to make sure it accepts unicode
> strings and if so, what types (utf-8, 16, 32).
>
> See this post for a similar problem:
>
> http://lists.modevia.com/archives/py-transports/2005-December/001719....
>
> and this link details tuple usage:http://www.faqs.org/docs/diveintopython/odbchelper_tuple.html
>
> Mike

I tried adding .encode("utf-8") onto each of the variables in the
tuple, but that didn't seem to help.  The error just changes slightly
to AttributeError: 'long' object has no attribute 'encode'

I'm using Mysql.




More information about the Python-list mailing list