Newbie help (TypeError: int argument required)

Discussion in 'Python' started by Iain Adams, Jun 8, 2008.

  1. Iain Adams

    Iain Adams Guest

    Hi,

    I am new to python. I have been having trouble using the MysqlDB. I
    get an error pointing from the line

    cursor.execute("UPDATE article SET title = %s, text = %s WHERE id =
    %u", (self.title, self.text, self.id))

    Here is the error:

    line 56, in save
    cursor.execute("UPDATE article SET title = %s, text = %s WHERE id
    = %u", (self.title, self.text, self.id))
    File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
    151, in execute
    query = query % db.literal(args)
    TypeError: int argument required

    However when I print out type(self.id) I get <type 'int'>.

    So surely I have provided an int argument.

    Any ideas anyone??
     
    Iain Adams, Jun 8, 2008
    #1
    1. Advertising

  2. Iain Adams

    Guest

    On Jun 8, 1:43 pm, Iain Adams <> wrote:
    > Hi,
    >
    > I am new to python. I have been having trouble using the MysqlDB. I
    > get an error pointing from the line
    >
    > cursor.execute("UPDATE article SET title = %s, text = %s WHERE id =
    > %u", (self.title, self.text, self.id))
    >
    > Here is the error:
    >
    >  line 56, in save
    >     cursor.execute("UPDATE article SET title = %s, text = %s WHERE id
    > = %u", (self.title, self.text, self.id))
    >   File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
    > 151, in execute
    >     query = query % db.literal(args)
    > TypeError: int argument required
    >
    > However when I print out type(self.id) I get <type 'int'>.
    >
    > So surely I have provided an int argument.
    >
    > Any ideas anyone??

    From MySQLdb User's Guide (http://mysql-python.sourceforge.net/
    MySQLdb.html):

    To perform a query, you first need a cursor, and then you can execute
    queries on it:

    c=db.cursor()
    max_price=5
    c.execute("""SELECT spam, eggs, sausage FROM breakfast
    WHERE price < %s""", (max_price,))

    In this example, max_price=5 Why, then, use %s in the string? Because
    MySQLdb will convert it to a SQL literal value, which is the string
    '5'. When it's finished, the query will actually say, "...WHERE price
    < 5".
     
    , Jun 8, 2008
    #2
    1. Advertising

  3. Iain Adams

    bukzor Guest

    On Jun 8, 11:43 am, Iain Adams <> wrote:
    > Hi,
    >
    > I am new to python. I have been having trouble using the MysqlDB. I
    > get an error pointing from the line
    >
    > cursor.execute("UPDATE article SET title = %s, text = %s WHERE id =
    > %u", (self.title, self.text, self.id))
    >
    > Here is the error:
    >
    >  line 56, in save
    >     cursor.execute("UPDATE article SET title = %s, text = %s WHERE id
    > = %u", (self.title, self.text, self.id))
    >   File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
    > 151, in execute
    >     query = query % db.literal(args)
    > TypeError: int argument required
    >
    > However when I print out type(self.id) I get <type 'int'>.
    >
    > So surely I have provided an int argument.
    >
    > Any ideas anyone??


    Change your u to an s and you'll be fine. If you want a specific
    format on the integer, format it first and pass in the string.
     
    bukzor, Jun 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,227
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,657
    Old Wolf
    Jan 20, 2004
  3. lucius
    Replies:
    14
    Views:
    1,534
    Lie Ryan
    Jun 18, 2009
  4. Íéêüëáïò Êïýñáò

    TypeError: iterable argument required

    Íéêüëáïò Êïýñáò, Apr 2, 2011, in forum: Python
    Replies:
    3
    Views:
    312
    Íéêüëáïò Êïýñáò
    Apr 2, 2011
  5. eryksun ()
    Replies:
    3
    Views:
    505
    Íéêüëáïò Êïýñáò
    Apr 4, 2011
Loading...

Share This Page