gpt4 book ai didi

python - 带有 Python 的 Cassandra 3.7, 'NoneType' 对象没有属性 'encode_message'

转载 作者:太空宇宙 更新时间:2023-11-04 03:03:29 25 4
gpt4 key购买 nike

我有一个简单的 python 客户端来从 cassandra 获取数据。查询字符串本身使用 DBeaver EE 客户端运行良好。

def getDataSet(self, station_id, tablename):
prepared_stmt = self.session.prepare ( "SELECT event_time, reading FROM " +
tablename + " WHERE station_id = ?;")
bound_stmt = prepared_stmt.bind([station_id])
rslt = self.session.execute(bound_stmt)
df = pd.DataFrame()
for r in rslt:
df = df.append(r)
return df

def __init__(self):
cluster = Cluster(
contact_points=['127.0.0.1'],
)
self.session = cluster.connect('data')
self.session.row_factory = tuple_factory
self.session.client_protocol_handler = NumpyProtocolHandler

我得到以下异常

File "/home/david/git/python-example/src/start/fetchcassandra.py", line 13, in getDataSet
rslt = self.session.execute(bound_stmt)
File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 1961, in execute
return self.execute_async(query, parameters, trace, custom_payload, timeout, execution_profile).result()
File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 3649, in result
raise self._final_exception
cassandra.cluster.NoHostAvailable: ('Unable to complete the operation against any hosts', {<Host: 127.0.0.1 datacenter1>: AttributeError("'NoneType' object has no attribute 'encode_message'",)})

最佳答案

很可能未构建 NumpyProtocolHander,因此您将指定 None 作为协议(protocol)处理程序。

参见 here有关安装说明,并查阅您的 pip 日志以获取有关未构建它的原因的线索。

关于python - 带有 Python 的 Cassandra 3.7, 'NoneType' 对象没有属性 'encode_message',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40206004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com