peewee: Problem with pymysql + python 2.7
Came across this problem when running a full test suite using pymysql with Python 2.7.
If you attempt to pass in a binary to BlobField, it results in the following error upon execution.
build/bdist.linux-x86_64/egg/peewee.py:4494: in create
???
build/bdist.linux-x86_64/egg/peewee.py:4680: in save
???
build/bdist.linux-x86_64/egg/peewee.py:3213: in execute
???
build/bdist.linux-x86_64/egg/peewee.py:2628: in _execute
???
build/bdist.linux-x86_64/egg/peewee.py:3454: in execute_sql
???
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/cursors.py:156: in execute
query = self.mogrify(query, args)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/cursors.py:135: in mogrify
query = query % self._escape_args(args, conn)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/cursors.py:110: in _escape_args
return tuple(conn.escape(arg) for arg in args)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/cursors.py:110: in <genexpr>
return tuple(conn.escape(arg) for arg in args)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/connections.py:781: in escape
return escape_item(obj, self.charset, mapping=mapping)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/converters.py:26: in escape_item
val = encoder(val, mapping)
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/converters.py:109: in escape_unicode
return u"'%s'" % _escape_unicode(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = <read-only buffer for 0x7f4027d59880, size -1, offset 0 at 0x7f4027d653f0>, mapping = None
def _escape_unicode(value, mapping=None):
"""escapes *value* without adding quote.
Value should be unicode
"""
> return value.translate(_escape_table)
E AttributeError: 'buffer' object has no attribute 'translate'
mapping = None
value = <read-only buffer for 0x7f4027d59880, size -1, offset 0 at 0x7f4027d653f0>
.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/converters.py:72: AttributeError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /vagrant/peewee-extras/.eggs/PyMySQL-0.7.2-py2.7.egg/pymysql/converters.py(72)_escape_unicode()
-> return value.translate(_escape_table)
Code to reproduce the problem;
class TestModel(Model):
value = BlobField()
v = binascii.unhexlify('0a0a0a')
OrderedUUIDModel.create(value=str(v))
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (10 by maintainers)
I was having all sorts of problems like this with PyMySQL (0.7.2 and 0.6.6). I switched to MySQLdb and everything is good.