0

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()
Arpit
  • 99
  • 12

1 Answers1

1

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"
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895