我正在编写一个使用 SQLAlchemy 调用脚本的 django 应用程序。以下查询使用 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)
使用 Python v3.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