Skip to content

Connection.escape fails to escape byte strings and raises TypeError: bytes() argument 2 must be str, not dict. #489

Closed
@rsiemens

Description

@rsiemens

Describe the bug

MySQL 8.0.23
Python 3.8.5
mysqlclient 2.0.3

Connection.escape fails to escape byte strings and raises TypeError: 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 -

  • Have a MySQL server running and connect to it
import MySQLdb
conn = MySQLdb.connect(user='root', host='localhost', port=33060)
conn.escape(b'foo', conn.encoders)
>> TypeError: bytes() argument 2 must be str, not dict

Environment

MySQL Server

  • Server OS (e.g. Windows 10, Ubuntu 20.04): MacOS 10.15.7
  • Server Version (e.g. MariaDB 10.3.16): MySQL 8.0.23

MySQL Client

  • OS (e.g. Windows 10, Ubuntu 20.04): MacOS 10.15.7
  • Python (e.g. Homebrew Python 3.7.5): 3.8.5
  • mysqlclient 2.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions