Problems with my string and pgdb and .execute()
От | Alastair G. Hogge |
---|---|
Тема | Problems with my string and pgdb and .execute() |
Дата | |
Msg-id | 200308171925.50615.agh@tpg.com.au обсуждение исходный текст |
Список | pgsql-interfaces |
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()
В списке pgsql-interfaces по дате отправления: