Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Newbie help (TypeError: int argument required)

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


aca04iba at shef

Jun 8, 2008, 11:43 AM

Post #1 of 3 (2733 views)
Permalink
Newbie help (TypeError: int argument required)

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??
--
http://mail.python.org/mailman/listinfo/python-list


shubalubdub at gmail

Jun 8, 2008, 12:56 PM

Post #2 of 3 (2672 views)
Permalink
Re: Newbie help (TypeError: int argument required) [In reply to]

On Jun 8, 1:43 pm, Iain Adams <aca04...@shef.ac.uk> 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".
--
http://mail.python.org/mailman/listinfo/python-list


workitharder at gmail

Jun 8, 2008, 10:46 PM

Post #3 of 3 (2669 views)
Permalink
Re: Newbie help (TypeError: int argument required) [In reply to]

On Jun 8, 11:43 am, Iain Adams <aca04...@shef.ac.uk> 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.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.