Python3 and SQLAlchemy: TypeError when connecting to mysql #83

Closed
manubo opened this Issue Oct 10, 2011 · 5 comments

Comments

Projects
None yet
6 participants

manubo commented Oct 10, 2011

In Python3 I tried the following with SQLAlchemy 0.7.2:

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.

Thanks I resolved too.

Python3 requires "pymysql3"
[CODE]
sudo pip install pymysql3==0.4
[/CODE]

Thanks.
But why this isn't fixed in the code?

mmoya commented Feb 9, 2013

Still present in PyMySQL3==0.5. Resolved with @manubo's suggestion with a minor tweak: changing line 105 in cursors.py to:

query = query.decode(charset) % escaped_args

using conn.escape(args) didn't worked for me.

kdochez commented Feb 18, 2013

thanks a lot manubo it works perfect!!!

@antigenius antigenius added a commit to antigenius/PyMySQL that referenced this issue Jul 10, 2013

@antigenius antigenius Patch file added for issue #83, PyMySQL#83 82d022a
Owner

lecram commented Sep 21, 2013

Fixed in a8dd44d.

lecram closed this Sep 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment