"ProgrammingError: can't adapt" when passing arguments to cursor.execute
William Carithers <wccarithers-/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <C72B0A3D.10A36%[email protected]> |
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.
Thanks in advance,
Bill
Here's the offending snippit of script code:
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']
if options.debug:
print load
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)
Here's the terminal output (starting with the print output from the debug
option:
[3536, 55098, 507, 2.3787246, 'QSO', False, True, False, False, True, False,
True, True, False, 3.0264823, 5.2976532, 7.3849945, 8.8946981, 12.131689,
'unscanned']
Traceback (most recent call last):
File "./loadDB.py", line 116, in <module>
sys.exit(main())
File "./loadDB.py", line 86, in main
curs.execute(query, load)
psycopg2.ProgrammingError: can't adapt
However when I execute the exact same snippet from an interactive terminal,
it works fine. Here's the terminal output:
>>> load
[3536, 55098, 507, 2.3787246, 'QSO', False, True, False, False, True, False,
True, True, False, 3.0264823000000001, 5.2976532000000001,
7.3849945000000004, 8.8946980999999994, 12.131689, 'unscanned']
>>> 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)
>>> conn.commit()