Re: "ProgrammingError: can't adapt" when passing arguments to cursor.execute

Tim Roberts <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization Providenza & Boekelheide, Inc.
Message-ID <[email protected]>
William Carithers wrote:
> I'm trying to pass a list of arguments to an cursor.execute statement in a
> Python script and I get the "can't adapt" error. However, when I execute the
> same code snippet interactively, it works fine. Obviously, I'm missing
> something here but I can't find it.
>   

My GUESS is that you're somehow picking up a different versions of
Python when you run it.  Perhaps your #! line has an absolute path
different from what you get at the command line.

The versions of psycopg I'm familiar with don't accept lists as the
argument, only tuples.  So:

> query = """INSERT INTO flags
>                         VALUES
> (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
>
> curs.execute(query, load)
>   

Change that to:
    curs.execute( query, tuple(load) )
and I'll bet it works.

Or, change
> load = [int(plate), int(mjd), fiber, z, id_type, flg[0],
> flg[1],flg[2],flg[3], flg[4], flg[5],
>   flg[6], flg[7], flg[8], spflux[0], spflux[1], spflux[2], spflux[3],
> spflux[4],'unscanned']

to

load = (int(plate), int(mjd), fiber, z, id_type, flg[0], flg[1],flg[2],flg[3], flg[4], flg[5],
  flg[6], flg[7], flg[8], spflux[0], spflux[1], spflux[2], spflux[3], spflux[4],'unscanned')

-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.