X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id AED0AD1B89B for ; Sun, 17 Aug 2003 09:25:54 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35749-05 for ; Sun, 17 Aug 2003 06:25:46 -0300 (ADT) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by svr1.postgresql.org (Postfix) with ESMTP id 85CDCD1B8A4 for ; Sun, 17 Aug 2003 06:25:42 -0300 (ADT) Received: from 192.168.0.4 (220-244-72-6.tpgi.com.au [220.244.72.6]) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id h7H9Pf007402 (using TLSv1/SSLv3 with cipher RC4-MD5 (128 bits) verified NO) for ; Sun, 17 Aug 2003 19:25:42 +1000 From: "Alastair G. Hogge" To: pgsql-interfaces@postgresql.org Subject: Problems with my string and pgdb and .execute() Date: Sun, 17 Aug 2003 19:25:50 +1000 User-Agent: KMail/1.5.3 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308171925.50615.agh@tpg.com.au> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/51 X-Sequence-Number: 4405 Hello all, I'm trying desperately to get my code working. I use Python to retrieve information from a HTML form (CGI). I then want to store this info in my PostgreSQL database. So first I get the info in the form keys and concate them to a string. As I understand it, the .execute funtion of pgdb likes the format ('one','two') so I make a string to represent that. But when I try to store the info I get the following from the cur.execute("INSERT INTO house VALUES (%s)" % (final_qu)) line in my code. TypeError: not all arguments converted during string formatting, So my code: #!/usr/local/bin/python import cgi import time import pgdb # Begin form = cgi.FieldStorage() # Grab the data from web page form qu = str("") for name in form.keys(): qu += "'" + str((form[name].value)) + "'," # At this stage qu would be something like "('one','hello','test','1232') tail = "'" + str(time.strftime("%Y-%m-%d")) + "','" + str(time.strftime("%H:%M:%S")) + "'" final_qu = SeAnRe.Action("'Submit',", tail, qu) db = pgdb.connect(dsn=_dbsource, user=_dbuser, database=_dbname) cur = db.cursor() cur.execute("INSERT INTO house VALUES (%s)" % (final_qu)) db.commit() cur.close() db.close()