petehunt/PyMySQL — Issue #83: Python3: TypeError when connecting to mysql
Author: mbouza
Created: 2011-10-10 16:16:22+00:00
State: open

In Python3 I tried the following:

engine = sqlalchemy.create_engine("mysql+pymysql://root:123456@localhost/alchemy")
conn = engine.connect()

And got the following error:

File "/usr/local/.../pymysql/cursors.py", line 96, in execute
query = query % conn.escape(args)
TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'

Changing line 96 in cursors.py to

query = query.decode(charset) % conn.escape(args)

solved the problem.