Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie help (TypeError: int argument required)

Reply
Thread Tools

Newbie help (TypeError: int argument required)

 
 
Iain Adams
Guest
Posts: n/a
 
      06-08-2008
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??
 
Reply With Quote
 
 
 
 
shubalubdub@gmail.com
Guest
Posts: n/a
 
      06-08-2008
On Jun 8, 1:43*pm, Iain Adams <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
 
bukzor
Guest
Posts: n/a
 
      06-09-2008
On Jun 8, 11:43*am, Iain Adams <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why is int a[0] not allowed, but int* a = new int[0] is? haijin.biz@gmail.com C++ 9 04-17-2007 09:01 AM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments