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()