hello, plz help to figure out one problem I am new to Python
and really going crazy.... about errors
I have DB, I must insert data with CGI scripts I am using python. However I get erro msg. operational error. Data is read from form values.
here is the code:
if len(form.keys()) > 0:
wname = str(form.getvalue("warehouse"))
pname= str(form.getvalue("product_name"))
aid = int(form.getvalue("amount"))
if wname:
m = re.match('^[a-zA-Z\'\- ]*$', wname)
if m:
cursor.execute("SELECT distinct id " +
"FROM warehouse w " +
"WHERE w.name ILIKE %(tname)s",
{ "tname": "%" + wname + "%" } )
tt = cursor.fetchone()
else:
print "<h2>Invalid Parameter</h2>"
print cgi.escape( substring )
print "'</p>"
sys.exit()
if pname:
m = re.match('^[a-zA-Z\'\- ]*$', pname)
if m:
cursor.execute("SELECT distinct id " +
"FROM product p " +
"WHERE p.name ILIKE %(tname)s",
{ "tname": "%" + pname + "%" } )
pid = cursor.fetchone()
else:
print "<h2>Invalid Parameter</h2>"
print cgi.escape( substring )
print "'</p>"
sys.exit()
import random
import datetime
cursor.execute( "INSERT INTO shipment (id,wh_id,pt_id,date,amount)" +
"VALUES (%(id)i,%(wh_id)i, %(pt_id)i,%(datetime)i,%(amount)i)",
{ "wh_id":tt,
"pt_id"id,
"amount":int(aid),
"id" :random.randint(8,500),
"datetime":datetime.date.today()} )
db.commit()
ERROR===========================
OperationalError Python 2.4.3: /usr/bin/python
Sun Nov 16 14:32:42 2008
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/disk/homewikipages/homepages/s0894238/cgi/hello_world
135 cursor.execute( "INSERT INTO shipment (id,wh_id,pt_id,date,amount)" +
136 "VALUES (%(id)i,%(wh_id)i, %(pt_id)i,%(datetime)i,%(amount)i)",
137 { "wh_id":tt,
138 "pt_id"id,
139 "amount":int(aid),
tt = [12], pid = [63], builtin int = <type 'int'>, aid = 500, random = <module 'random' from '/usr/lib/python2.4/random.pyc'>, random.randint = <bound method Random.randint of <random.Random object>>, datetime = <module 'datetime' from '/usr/lib/python2.4/lib-dynload/datetime.so'>, datetime.date = <type 'datetime.date'>, datetime.date.today = <built-in method today of type object>
/usr/lib/python2.4/site-packages/pgdb.py in execute(self=<pgdb.pgdbCursor instance>, operation='INSERT INTO shipment (id,wh_id,pt_id,date,amount...d)i,%(wh_id)i, %(pt_id)i,%(datetime)i,%(amount)i)', params={'amount': 500, 'datetime': datetime.date(2008, 11, 16), 'id': 283, 'pt_id': [63], 'wh_id': [12]})
173 else:
174 # not a list of tuples
175 self.executemany(operation, (params,))
176
177 def executemany(self, operation, param_seq):
self = <pgdb.pgdbCursor instance>, self.executemany = <bound method pgdbCursor.executemany of <pgdb.pgdbCursor instance>>, operation = 'INSERT INTO shipment (id,wh_id,pt_id,date,amount...d)i,%(wh_id)i, %(pt_id)i,%(datetime)i,%(amount)i)', params = {'amount': 500, 'datetime': datetime.date(2008, 11, 16), 'id': 283, 'pt_id': [63], 'wh_id': [12]}
/usr/lib/python2.4/site-packages/pgdb.py in executemany(self=<pgdb.pgdbCursor instance>, operation='INSERT INTO shipment (id,wh_id,pt_id,date,amount...d)i,%(wh_id)i, %(pt_id)i,%(datetime)i,%(amount)i)', param_seq=({'amount': 500, 'datetime': datetime.date(2008, 11, 16), 'id': 283, 'pt_id': [63], 'wh_id': [12]},))
196 raise DatabaseError, "error '%s' in '%s'" % ( msg, sql )
197 except Exception, err:
198 raise OperationalError, "internal error in '%s': %s" % (sql,err)
199 except:
200 raise OperationalError, "internal error in '%s'" % sql
global OperationalError = <class pg.OperationalError>, sql = 'INIT', err = <exceptions.TypeError instance>
OperationalError: internal error in 'INIT': int argument required
args = ("internal error in 'INIT': int argument required",)
PLZ HELP

id,
Reply With Quote



