Arpit
Arpit

Reputation: 109

Getting error while using MySQLdb.cursors.DictCursor in MYSQL_CURSORCLASS

In my Flask application, in order to get results in dictionary format in MySQLdb, I added the statement:

app.config['MYSQL_CURSORCLASS'] = MySQLdb.cursors.DictCursor

I got the error

kwargs['cursorclass'] = getattr(MySQLdb.cursors, current_app.config['MYSQL_CURSORCLASS'])

TypeError: getattr(): attribute name must be string

My application was running perfectly fine before adding this statement. After some searching, I found out that the error seems to be caused by the given line

db = mysql.connection.cursor()

Upvotes: 1

Views: 1944

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Like the error says, that setting needs to be a string which is then used to look up the cursor class in MySQLdb.cursors.

app.config['MYSQL_CURSORCLASS'] = "DictCursor"

Upvotes: 2

Related Questions