Bug #64392 MySQLCursor.description stores column names as bytes literals
Submitted: 21 Feb 2012 9:09 Modified: 29 Jun 2012 8:45
Reporter: Geert Vanderkelen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:0.3.2 OS:Any
Assigned to: Geert Vanderkelen CPU Architecture:Any

[21 Feb 2012 9:09] Geert Vanderkelen
Description:
Using Python 3.1, the column names in MySQLCursor.description are stored as bytes literals. 

How to repeat:
import mysql.connector

def main():
    cnx = mysql.connector.connect(user='root',database='test')
    cursor = cnx.cursor()
    cursor.execute("SELECT 1 as 'ham', 2 as 'spam'")
    cursor.fetchall()
    print(cursor.description)
    cursor.close()
    cnx.close()

if __name__ == '__main__':
    main()

# result: [(b'ham', 8, None, None, None, None, 0, 129), (b'spam', 8, None, None, None, None, 0, 129)]

Suggested fix:
Decode the column names using the correct character set into unicode.
[21 Feb 2012 9:15] Geert Vanderkelen
Verified using Python 3.2.2 and latest code from source repository.

Workaround is to do the decoding when showing/using the column names, something like this:
    for column in cursor.description:
        print("Column: {name}".format(name=column[0].decode()))
[29 Jun 2012 8:45] Geert Vanderkelen
This is fixed and will be available in next release.