mysqldb bytes error

Bug #1800881 reported by Илья Коваленко
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
python-mysqldb (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

The version of the library provided in the distribution contains an error.

TypeError: a bytes-like object is required, not 'str'

This bug is fixed in the library version 1.3.13 or can be fixed by a patch:

--- MySQLdb/cursors.py.orig
+++ MySQLdb/cursors.py
@@ -21,7 +21,17 @@
else:
   text_type = str

-
+def convert_to_str(var):
+ if isinstance(var,tuple):
+ return tuple(convert_to_str(item) for item in var)
+ if isinstance(var,list):
+ return ([convert_to_str(item) for item in var])
+ elif isinstance(var,dict):
+ return {convert_to_str(key):convert_to_str(value) for key,value in var.items()}
+ elif isinstance(var,bytes):
+ return var.decode('utf-8')
+ else:
+ return var
#: Regular expression for :meth:`Cursor.executemany`.
#: executemany only supports simple bulk insert.
#: You can use it to load large dataset.
@@ -443,6 +453,9 @@
       else:
           result = self._rows
       self.rownumber = len(self._rows)
+ if not PY2:
+ db = self._get_db()
+ result = tuple(convert_to_str(result))
       return result

   def scroll(self, value, mode='relative'):

Please upgrade version lib or apply this patch.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-mysqldb (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.