简体   繁体   中英

How can I access ScyllaDB in Docker container using Python?

I have set up Docker container with ScyllaDB in accordance to the official doc . 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. 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. The 9160 is the thrift port, which is less used these days. 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.

You might want to do the following. First make sure that ScyllaDB nodes are up using

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.

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 172.17.0.2

Otherwise, just put it into your Python script and run it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM