473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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??
Jun 27 '08 #1
2 4598
On Jun 8, 1:43*pm, Iain Adams <aca04...@shef.ac.ukwrote:
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 WHEREid
= %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 27 '08 #2
On Jun 8, 11:43*am, Iain Adams <aca04...@shef.ac.ukwrote:
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 WHEREid
= %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.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2...
3
by: Manish Gupta (BBS) | last post by:
Hello invoking something like following - sock.send(100) generates the following error - TypeError: send() argument 1 must be string or read-only buffer, not int
0
by: Huzaifa Tapal | last post by:
I am getting this error from python 2.3.5 when making secure socket connections from my mod_python based application. It is very odd because we cannot replicate this in the development...
4
by: arotem | last post by:
Hi, I am trying to call an unbound method (PrintInput) with the object instance as the first argument but getting the following error: "TypeError: unbound method PrintInput() must be called with...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
10
by: codefire | last post by:
Hi, I have some simple code - which works...kind of..here's the code: import os def print_tree(start_dir): for f in os.listdir(start_dir): fp = os.path.join(start_dir, f)
3
Eclipse
by: Eclipse | last post by:
G'day All I am just starting to learn programming and need a bit of help with this one. I want to be able to create a list containing Path, Directory, Filename and write them out to a csv file...
4
by: Johannes Bauer | last post by:
Hello group, I'm currently doing something like this: import time localtime = time.localtime(1234567890) fmttime = "%04d-%02d-%02d %02d:%02d:%02d" % (localtime, localtime, localtime,...
0
by: John Krukoff | last post by:
On Fri, 2008-10-31 at 08:55 +1000, James Mills wrote: Are you sure? It looks like his complaint isn't that it doesn't work, but that the error message is misleading. With the setup: Python...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.