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()

I don't get it.

Something weird. :D

Can you post the db.

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

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,

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'

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?

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...

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.