Johanna Johanna - 1 year ago 111
Python Question

Mysqldb AttributeError: cursor

I am starting to use the mysqldb module in python and I seem to have some issues with the "standard" way of calling queries.

I understand that the standard way is to create a cursor and then use it to execute queries.

However, when I try to instanciate one, it gives me the following error :

AttributeError: cursor

My Database class looks like :

class Database():

def __init__(self):
server = "localhost"
login = "login"
password = "passws"
database = "DB"
my_conv = { FIELD_TYPE.LONG: int }

self.conn = MySQLdb.connection(user=login, passwd=password, db=database, host=server, conv=my_conv)
self.cursor = self.conn.cursor()

def close(self):

def execute(self, query):
return self.cursor.fetchall()

For now I get it working by using the query method, but I feel not using the standard will give me trouble in the future.

Any idea ?

Answer Source

You are using wrong connection constructor.

MySQLdb.Connection instead of MySQLdb.connection should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download