python3 SqlAlchemy错误TypeError:类型str不支持缓冲区API

时间:2015-01-27 19:15:43

标签: python sql django sqlalchemy oursql

我正在编写一个使用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

1 个答案:

答案 0 :(得分:1)

我猜我们的pyql在python3中没有正确连接。我切换到mysqlconnector,它工作正常。