| Bug #74345 | connector/python can't report errors that have non-ascii characters, as of 2.0 | ||
|---|---|---|---|
| Submitted: | 13 Oct 2014 0:31 | Modified: | 14 Nov 2014 14:49 |
| Reporter: | Mike Bayer | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / Python | Severity: | S2 (Serious) |
| Version: | 2.0.1 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[13 Oct 2014 8:19]
MySQL Verification Team
Hello Mike Bayer, Thank you for the report and test case. Thanks, Umesh
[13 Oct 2014 8:19]
MySQL Verification Team
// [root@cluster-repo master]# rpm -qa|grep mysql-connector-python mysql-connector-python-commercial-2.0.1-1.el6.noarch [root@cluster-repo master]# python Python 2.6.6 (r266:84292, Jan 22 2014, 01:49:05) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> from mysql import connector character = u'\u6e2c\u8a66' conn = connector.connect( user='root', password='', host='localhost', database='test') >>> character = u'\u6e2c\u8a66' >>> >>> conn = connector.connect( ... user='root', password='', host='localhost', database='test') >>> >>> cursor = conn.cursor() >>> sql = u"create table %s (id integer)" % character >>> >>> for i in range(2): ... try: ... cursor.execute(sql) ... except connector.ProgrammingError as exc: ... print(exc) ... break ... Traceback (most recent call last): File "<stdin>", line 3, in <module> File "/mysql/connector/cursor.py", line 507, in execute File "/mysql/connector/connection.py", line 720, in cmd_query File "/mysql/connector/connection.py", line 638, in _handle_result File "/mysql/connector/errors.py", line 165, in get_exception File "/mysql/connector/errors.py", line 130, in get_mysql_exception File "/mysql/connector/errors.py", line 197, in __init__ UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)
[14 Nov 2014 14:49]
Paul DuBois
Noted in 2.0.3, 2.1.2 changelogs. Error messages containing non-ASCII characters caused an exception to be raised.

Description: this script attempts to create a table with a non-ascii name, and is expected to fail with a ProgrammingError. The script passes in Python 3, and in Python 2 when using MySQL-connector-python 1.1.6. However it fails with version 2.0.1 in python 2k: from mysql import connector character = u'\u6e2c\u8a66' conn = connector.connect( user='scott', password='tiger', host='localhost', database='test') cursor = conn.cursor() sql = u"create table %s (id integer)" % character for i in range(2): try: cursor.execute(sql) except connector.ProgrammingError as exc: print(exc) break output, with python 2 and version 2.0.1: Traceback (most recent call last): File "test.py", line 13, in <module> cursor.execute(sql) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/cursor.py", line 507, in execute self._handle_result(self._connection.cmd_query(stmt)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/connection.py", line 720, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/connection.py", line 638, in _handle_result raise errors.get_exception(packet) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/errors.py", line 165, in get_exception return get_mysql_exception(errno, errmsg, sqlstate) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/errors.py", line 130, in get_mysql_exception msg=msg, errno=errno, sqlstate=sqlstate) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/errors.py", line 197, in __init__ self._full_msg = fmt.format(**fields) UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128) How to repeat: run this script: from mysql import connector character = u'\u6e2c\u8a66' conn = connector.connect( user='scott', password='tiger', host='localhost', database='test') cursor = conn.cursor() sql = u"create table %s (id integer)" % character for i in range(2): try: cursor.execute(sql) except connector.ProgrammingError as exc: print(exc) break