pythondockercassandradatastaxcassandra-python-driver

Python Cassandra driver: connect to Docker container on server - cassandra.UnresolvableContactPoints: {}


I am runnning cassandra in a docker container on a custom server.

I start cassandra docker like this:

docker run  --name cassandra -p 9042:9042 -d cassandra:latest

When i want to conect to the server via the python cassandra driver from datastax like this:

from cassandra.cqlengine import connection

connection.setup(["http://myserver.myname.com"], "cqlengine", protocol_version=3)

The exception is thrown:

    File "C:\LONG\PATH\TO\venv\lib\site-packages\cassandra\cqlengine\connection.py", line 106, in setup
        self.cluster = Cluster(self.hosts, **self.cluster_options)
      File "cassandra\cluster.py", line 1181, in cassandra.cluster.Cluster.__init__

    cassandra.UnresolvableContactPoints: {}
python-BaseException

After hours of searching through docker network permissions I found the simple solution, so maybe this will help you too.


Solution

  • The simple solution is removing "http://" from the server url and changing my code from

    connection.setup(["http://myserver.myname.com"], "cqlengine", protocol_version=3)
    

    To

    connection.setup(["myserver.myname.com"], "cqlengine", protocol_version=3)
    

    I thought its a docker networking issue and it took me many hours to pin it down to this simple mistake