Closed Ferguzz closed 7 years ago
I can not reproduce this error. Can you give me more information?
$ python --version
Python 2.7.10
$ mysql --version
mysql Ver 14.14 Distrib 5.6.20, for osx10.9 (x86_64) using EditLine wrapper
$ virtualenv env
New python executable in /python/env/bin/python
Installing setuptools, pip, wheel...done.
$ env/bin/pip install tormysql
Collecting tormysql
Collecting PyMySQL>=0.7.3 (from tormysql)
Using cached PyMySQL-0.7.9-py2-none-any.whl
Collecting tornado>=4.1 (from tormysql)
Collecting greenlet>=0.4.2 (from tormysql)
Collecting backports.ssl-match-hostname (from tornado>=4.1->tormysql)
Collecting backports-abc>=0.4 (from tornado>=4.1->tormysql)
Using cached backports_abc-0.4-py2.py3-none-any.whl
Collecting certifi (from tornado>=4.1->tormysql)
Using cached certifi-2016.9.26-py2.py3-none-any.whl
Collecting singledispatch (from tornado>=4.1->tormysql)
Using cached singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting six (from singledispatch->tornado>=4.1->tormysql)
Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: PyMySQL, backports.ssl-match-hostname, backports-abc, certifi, six, singledispatch, tornado, greenlet, tormysql
Successfully installed PyMySQL-0.7.9 backports-abc-0.4 backports.ssl-match-hostname-3.5.0.1 certifi-2016.9.26 greenlet-0.4.10 singledispatch-3.4.0.3 six-1.10.0 tormysql-0.2.7 tornado-4.4.2
$ cat tormysql_test.py
import tormysql
import tornado
@tornado.gen.coroutine
def executemany():
try:
connection = yield tormysql.connect(**{
'host': '127.0.0.1',
'port': 13306,
'user': 'test',
'passwd': 'test',
'db': 'test',
})
cursor = connection.cursor()
yield cursor.execute("CREATE TEMPORARY TABLE users (email varchar(255), password varchar(255))")
yield cursor.executemany("INSERT INTO users (email, password) VALUES (%s, %s)", (
('tom@foo.com', 'very-secret'),
('dan@bar.com', 'no-so-secret'),
))
finally:
connection.close()
tornado.ioloop.IOLoop.current().run_sync(executemany)
$ env/bin/python tormysql_test.py
Traceback (most recent call last):
File "tormysql_test.py", line 27, in <module>
tornado.ioloop.IOLoop.current().run_sync(executemany)
File "/python/env/lib/python2.7/site-packages/tornado/ioloop.py", line 457, in run_sync
return future_cell[0].result()
File "/python/env/lib/python2.7/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "/python/env/lib/python2.7/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "tormysql_test.py", line 22, in executemany
('dan@bar.com', 'no-so-secret'),
File "/python/env/lib/python2.7/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/python/env/lib/python2.7/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "/python/env/lib/python2.7/site-packages/tormysql/util.py", line 14, in finish
result = fun(*args, **kwargs)
File "/python/env/lib/python2.7/site-packages/pymysql/cursors.py", line 193, in executemany
self._get_db().encoding)
File "/python/env/lib/python2.7/site-packages/pymysql/cursors.py", line 230, in _do_execute_many
rows += self.execute(sql + postfix)
File "/python/env/lib/python2.7/site-packages/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/python/env/lib/python2.7/site-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/python/env/lib/python2.7/site-packages/pymysql/connections.py", line 834, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/python/env/lib/python2.7/site-packages/pymysql/connections.py", line 1054, in _execute_command
self._write_bytes(packet)
File "/python/env/lib/python2.7/site-packages/tormysql/connections.py", line 316, in _write_bytes
self._sock.write(data)
File "/python/env/lib/python2.7/site-packages/tormysql/connections.py", line 139, in write
assert isinstance(data, bytes)
AssertionError
Already fixed, you can upgrade. very thanks.
Verified fixed. Thanks.
tormysql==0.2.6 on python 2.7.10 on osx
results in
I believe that this assertion is not correct, since it is pymysql under the hood which is converting our args to bytearrays. Should I just change the assertion to check for (bytes, bytearray) ?