[英]How can I access ScyllaDB in Docker container using Python?
I have set up Docker container with ScyllaDB in accordance to the official doc . 我已经根据官方文档使用ScyllaDB设置了Docker容器。 I created keyspace and table.
我创建了键空间和表。 Now I would like to insert some data to this table.
现在,我想向该表中插入一些数据。 I wonder have can I do this?
我想知道我能做得到吗? I found example:
我找到了例子:
import cql
con = cql.connect('localhost', 9160, 'logs', cql_version='3.0.0')
print ("Connected!")
cursor = con.cursor()
CQLString = "INSERT INTO event_attend (event_id, event_type, event_user_id) VALUES (131, 'Party', 3156);"
cursor.execute(CQLString)
however I get error shown below. 但是我得到如下所示的错误。 I can't find any examples that show how it could be done with Docker.
我找不到任何示例可以说明如何使用Docker来完成。 Any ideas?
有任何想法吗?
No handlers could be found for logger "thrift.transport.TSocket"
Traceback (most recent call last):
File "scylla_test.py", line 2, in <module>
con = cql.connect('localhost', 9160, 'logs', cql_version='3.0.0')
File "/usr/local/lib/python2.7/dist-packages/cql/connection.py", line 143, in connect
consistency_level=consistency_level, transport=transport)
File "/usr/local/lib/python2.7/dist-packages/cql/connection.py", line 59, in __init__
self.establish_connection()
File "/usr/local/lib/python2.7/dist-packages/cql/thrifteries.py", line 151, in establish_connection
self.transport.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TTransport.py", line 271, in open
return self.__trans.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TSocket.py", line 113, in open
raise TTransportException(TTransportException.NOT_OPEN, msg)
thrift.transport.TTransport.TTransportException: Could not connect to any of [('::1', 9160, 0, 0), ('127.0.0.1', 9160)]
Can you check with port 9042, which is the default CQL port. 您能否使用端口9042(默认的CQL端口)进行检查。 The 9160 is the thrift port, which is less used these days.
9160是节俭的端口,如今已很少使用。 Also, can you make sure you are forwarding the ports, for example:
另外,是否可以确保转发端口,例如:
docker run --name some-scylla \\ --volume /var/lib/scylla:/var/lib/scylla \\ -p 9042:9042 -p 7000:7000 -p 7001:7001 -p 7199:7199 \\ -p 9160:9160 -p 9180:9180 -p 10000:10000 \\ -d scylladb/scylla --overprovisioned 1
The 'localhost' address of the container is not accessible outside the container itself. 在容器本身外部无法访问容器的“ localhost”地址。
You might want to do the following. 您可能需要执行以下操作。 First make sure that ScyllaDB nodes are up using
首先确保ScyllaDB节点已使用
docker exec -it scylla nodetool status
It should output something similar to: 它应该输出类似于:
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 153.41 KB 256 100.0% 70a72849-5608-47d5-8c8d-0f1db0f57444 rack1
If the status of all nodes is "down" (DN) you might need to first bring them up. 如果所有节点的状态均为“关闭”(DN),则可能需要先将它们启动。
Now, use the displayed address of the node that is up. 现在,使用显示的节点地址。 If you have multiple nodes in your cluster, any of those addresses will do.
如果您的集群中有多个节点,则这些地址中的任何一个都可以。 You can first try to connect manually with cqlsh if it is installed in your system:
如果您的系统中已安装cqlsh,则可以首先尝试手动连接它:
cqlsh 172.17.0.2
Otherwise, just put it into your Python script and run it. 否则,只需将其放入您的Python脚本中并运行即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.