python3 SqlAlchemy error TypeError: Type str doesn't support the buffer API
python3 SqlAlchemy error TypeError: Type str doesn't support the buffer API
我正在编写一个使用 SQLAlchemy 调用脚本的 Django 应用程序。以下查询 运行s 成功 Python v2.x:
engine = create_engine('mysql+oursql://ag:529382Ag@localhost/gp?charset=utf8&use_unicode=0',pool_recycle=3600)
query = "select a.gid as entrez, a.source_id as "+id_dict[ids[0]]+", b.source_id as "+id_dict[ids[1]]+" from (select * from gid2source_id where gid2source_id.id_type_id = "+str(ids[0])+") a, (select * from gid2source_id where gid2source_id.id_type_id= "+str(ids[1])+") b where b.gid = a.gid;"
result1 = engine.execute(query)
当运行与Pythonv3.x时,收到如下错误:
line 105, in get_results result1 = engine.execute(query.decode('utf-8'))
...
line 2453, in initialize self._detect_ansiquotes(connection)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sqlalchemy/dialects/mysql/base.py",
line 2730, in _detect_ansiquotes
self._server_ansiquotes = 'ANSI_QUOTES' in mode TypeError: Type str doesn't support the buffer API
我猜 oursql 在 python3 中没有正确接口。我切换到 mysqlconnector 并且工作正常。
我正在编写一个使用 SQLAlchemy 调用脚本的 Django 应用程序。以下查询 运行s 成功 Python v2.x:
engine = create_engine('mysql+oursql://ag:529382Ag@localhost/gp?charset=utf8&use_unicode=0',pool_recycle=3600)
query = "select a.gid as entrez, a.source_id as "+id_dict[ids[0]]+", b.source_id as "+id_dict[ids[1]]+" from (select * from gid2source_id where gid2source_id.id_type_id = "+str(ids[0])+") a, (select * from gid2source_id where gid2source_id.id_type_id= "+str(ids[1])+") b where b.gid = a.gid;"
result1 = engine.execute(query)
当运行与Pythonv3.x时,收到如下错误:
line 105, in get_results result1 = engine.execute(query.decode('utf-8'))
...
line 2453, in initialize self._detect_ansiquotes(connection)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sqlalchemy/dialects/mysql/base.py",
line 2730, in _detect_ansiquotes
self._server_ansiquotes = 'ANSI_QUOTES' in mode TypeError: Type str doesn't support the buffer API
我猜 oursql 在 python3 中没有正确接口。我切换到 mysqlconnector 并且工作正常。