UnicodeDecodeError when creating IntegrityError on duplicate binary key
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MySQL Connector/Python |
In Progress
|
Medium
|
Geert JM Vanderkelen |
Bug Description
* Description:
When mysql connector attemps to generate the error message for an IntegrityError due to a duplicate binary key error, it attempts to convert the binary key to text resulting in an unicode decoding error.
Below is the stack trace produced by the attached sample:
Traceback (most recent call last):
File "C:\Python32\
errmsg = buf.decode('utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 17: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "binarypkduplic
main()
File "binarypkduplic
cursor.execute( stmt, (KEY2, 'comment') )
File "C:\Python32\
res = self.db(
File "C:\Python32\
return func(*args, **kwargs)
File "C:\Python32\
return self.handle_
File "C:\Python32\
errors.
File "C:\Python32\
% e)
mysql.connector
* Platform details:
python -c "import mysql.connector as db; print(db.
(0, 3, 2, 'devel', 292)
Python: 3.2
Mysql version: 5.0.51b-
O.S.: Windows XP SP2, 32 bits
Remember verifying this, but did not update the bug.. thanks for the great report!
Smaller test case:
cnx = mysql.connector .connect( database= 'test', charset= 'utf8') execute( 'DROP TABLE IF EXISTS t1') execute( 'CREATE TABLE t1 (c1 BINARY(1), UNIQUE KEY (c1))')
cur = cnx.cursor()
cur.
cur.
insert = "INSERT INTO t1 VALUES (%s)" execute( insert, (data,)) execute( insert, (data,))
data = (b'\x80')
cur.
cur.
cur.close()
cnx.close()
This is Python 3 specific, and we'll fix it like this in errors. raise_error( ) 'utf-8' ,'surrogateesca pe')
errmsg = buf.decode(
Maybe we can do something similar for Python v2, but