我在通过python驱动程序查询我的cassandra数据库时遇到问题。
我的cassandra版本是 python2.7
>>> import cassandra
>>> cassandra.__version__
'2.1.3'
>>>
我的代码:
def search_data(self, ticker):
row = self.session.execute("""select * from secmaster.ticker_name where ticker = %s""",(ticker))
print row
获取错误:
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1293, in execute
future = self.execute_async(query, parameters, trace)
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1342, in execute_async
future = self._create_response_future(query, parameters, trace)
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1373, in _create_response_future
query_string = bind_params(query_string, parameters, self.encoder)
File "/usr/local/lib/python2.7/dist-packages/cassandra/query.py", line 727, in bind_params
return query % tuple(encoder.cql_encode_all_types(v) for v in params)
TypeError: not all arguments converted during string formatting
但如果我在下面查询它确实有效
def search_data(self, ticker):
row = self.session.execute("""select * from secmaster.ticker_name""")
print row
答案 0 :(得分:3)
Session.execute
)或parameters
调用 tuple
参数dict
。请注意,将单个表达式括在括号中并不会使它成为单项元组;你必须添加一个尾随逗号,例如:
def search_data(self, ticker):
row = self.session.execute("""select * from secmaster.ticker_name where ticker = %s""",(ticker,))
print row
答案 1 :(得分:-3)
固定
row = self.session.execute(" select * from secmaster.ticker_name,其中ticker ='%s'"%ticker)