-
Notifications
You must be signed in to change notification settings - Fork 442
Connection.escape
fails to escape byte strings and raises TypeError: bytes() argument 2 must be str, not dict
.
#489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is not intended usage. It is so frustlating. Why Django use this library so complex way... |
@methane Thanks for an advice. I tried (django/django#14196) calling >>> conn.escape('μg/mL')
UnicodeEncodeError: 'ascii' codec can't encode character '\u03bc' in position 0: ordinal not in range(128) |
|
|
We use >>> conn.encoding
'utf8'
>>> conn.escape('μg/mL')
UnicodeEncodeError: 'ascii' codec can't encode character '\u03bc' in position 0: ordinal not in range(128)
>>> conn.escape('μg/mL', conn.encoders)
b"'\xce\xbcg/mL'"
Docs are confusing IMO: "escape any special characters in object obj using mapping dict to provide quoting functions for each type." We want to quote values for DDL statements. We would be grateful for any advice. Thanks. \cc @claudep |
You are right. I am not original author of this library, and I added ugly hack to workaround it. That's why So there is no simple right way to do it for now. |
@methane Thanks 👍 I've proposed adding a "temporary" workaround to Django, see django/django#14196. |
IMO, this can be closed. |
Describe the bug
MySQL 8.0.23
Python 3.8.5
mysqlclient 2.0.3
Connection.escape
fails to escape byte strings and raisesTypeError: bytes() argument 2 must be str, not dict
.At first I assumed this was a Django issue and raised it there (https://code.djangoproject.com/ticket/32595), but was pointed back here. I believe this is the offending code (https://github.com/PyMySQL/mysqlclient/blob/v2.0.1/MySQLdb/connections.py#L189-L194). Looking at the comment I think it can simply be removed as mysqlclient is on 2.x now and Django 1.11 is EOL.
To Reproduce
Simplest reproduction -
Environment
MySQL Server
MySQL Client
The text was updated successfully, but these errors were encountered: