×

Discussion Board

Results 1 to 2 of 2

Thread: STUCK

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    1

    Unhappy STUCK

    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

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: STUCK

    Hi g000g,

    Welcome to the Python DiBo

    Please click on the # symbol on the text editor for adding the code tag to your code, so you can save it's indentation, making it much more readable for the users


    BR,

    Rafael.

Similar Threads

  1. SMS stuck in outbox
    By JOM in forum Symbian
    Replies: 4
    Last Post: 2008-04-25, 04:06
  2. httplib stuck on response
    By roidayan in forum Symbian
    Replies: 2
    Last Post: 2008-01-28, 05:58
  3. Voice Mail Symbol Stuck
    By Benny Boy in forum General Development Questions
    Replies: 0
    Last Post: 2007-03-14, 16:25
  4. Stuck in My Very First Application :(
    By logistics0405 in forum Symbian
    Replies: 3
    Last Post: 2005-02-03, 16:51
  5. SMS stuck in Outbox :CSendAs
    By alvin_jdc in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-06-03, 03:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •