[Bug 1800881] [NEW] mysqldb bytes error

Илья Коваленко FFVIICCSephiroth at gmail.com
Wed Oct 31 16:49:46 UTC 2018


Public bug reported:

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.

** Affects: python-mysqldb (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to python-mysqldb in Ubuntu.
https://bugs.launchpad.net/bugs/1800881

Title:
  mysqldb bytes error

Status in python-mysqldb package in Ubuntu:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-mysqldb/+bug/1800881/+subscriptions



More information about the foundations-bugs mailing list