0

Hi. I'm fiddling around with Python and MySql. I keep getting an error with this little script to try and read the rows in a table.
The error is:
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

Here is the code snippet. Any help would be hugely appreciated

import pymysql
conn=pymysql.connect(host="localhost",user="root",passwd=None,db="grubstreet")
cur=conn.cursor()
cur.execute('SELECT * FROM wp_1_comments')
for r in cur:
    print r
    
cur.close()
conn.close()
3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by andrewtrench
0

Thanks. I could post db. This is a wordpress db that I'm using but I've tried other dbs too (about six including simple ones that I've created myself) and they all produce the same errors

0

The error is:
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

There isn't any "+" sign in the code you posted. How about posting the entire error message including the offending line of code,

0

Thanks. Here is the whole error message. As you will see, same error message on a different db.
Traceback (most recent call last):
File "C:/Python26/blackbook.py", line 4, in <module>
cur.execute('SELECT * FROM names')
File "C:\Python26\lib\site-packages\pymysql-0.2-py2.6.egg\pymysql\cursor.py", line 82, in execute
self.errorhandler(self, exc, value)
File "C:\Python26\lib\site-packages\pymysql-0.2-py2.6.egg\pymysql\connections.py", line 96, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

0

File "C:\Python26\lib\site-packages\pymysql-0.2-py2.6.egg\pymysql\connections.py"

We'll eliminate the easy stuff first. Do you have MySQL installed and is the MySQL server running?

0

Haha, Virtuoso Definitely...Funnily if I execute something else like "SHOW TABLES" then I get a result without an error ie. a list of tables. It only seems to be a problem when I try and query a table...

0

I got it. LOL Pretty easy also. :)

Because you should be doing a 'cur.prepare' and not an 'cur.execute'.

Execute for actions on the table, prepare for visualization.

0

Hi folks. Found another package which solved my problems. Thank you for all your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.