【发布时间】:2020-03-29 21:01:10
【问题描述】:
我在 GCP 上有一个 (Apache) Cassandra 节点集群,在一个 VM 上有 Python3。 使用“cqlsh --cqlshrc”可以运行我需要的查询而不会出现任何错误。 在 cqlshrc 里面有装扮时间戳和增加的连接超时。
[复制] 日期时间格式 = %m/%d/%Y %H:%M:%S
[连接] request_timeout = 6000
我在“~/.cassandra/”文件夹中也有“cqlshrc”文件,所以我可以在不将其作为参数传递的情况下使用它。 现在使用“cassandra-driver”的 Python 脚本想要与 Cassandra 对话并运行一些查询,但我得到了这个错误:
Traceback(最近一次调用最后一次):文件“queries.py”,第 10 行,在 query1() 文件“queries.py”,第 6 行,在 query1 中 rows = session.execute('SELECT count(*) FROM freeway_loopdata WHERE speed > 100 ALLOW FILTERING') 文件“cassandra/cluster.py”, 第 2345 行,在 cassandra.cluster.Session.execute 文件中 “cassandra/cluster.py”,第 4304 行,在 cassandra.cluster.ResponseFuture.result cassandra.ReadFailure:错误 来自服务器:code=1300 [副本无法执行读取] message="操作失败 - 收到 0 个响应和 1 个失败" info={'一致性': 'LOCAL_ONE', 'required_responses': 1, “received_responses”:0,“失败”:1}
这是由于不增加超时。 如何将 Python 脚本中的“cqlshrc”文件作为参数传递?
【问题讨论】:
-
我已经使用“Session.default_timeout=an integer”和“Session.request_timeout=an integer”来增加超时时间,失败了。
-
如何声明与数据库的连接?表的结构是什么?在
cassandra.yaml中,您如何声明listen_address值?使用ALLOW FILTERING语句是一种反模式。 -
另外,Python驱动与数据库建立连接的方式与
cqlshrc无关。 -
我建立连接的方式是:
from cassandra.cluster import Clustercluster = Cluster(['0.0.0.0'],port=9042)session = cluster.connect('cs588damon',wait_for_all_pools=True)session.request_timeout=60000session.execute('USE cs588damon') -
这段代码在我可以查询的同一台虚拟机上。在该 VM 上使用 cqlsh 的相同查询工作正常。
标签: python-3.x cassandra