[英]Unable to connect cassandra with python
I am trying to connect to cassandra from python , I have installed cassandra
as pip install pycassa
.When i am trying to connect to the cassandra
i am getting the following exception 我正在尝试从python连接到cassandra,我已经将cassandra
安装为pip install pycassa
。当我尝试连接到cassandra
时,出现以下异常
from pycassa.pool import ConnectionPool
pool = ConnectionPool('Keyspace1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pycassa/pool.py", line 382, in __init__
self.fill()
File "/usr/lib/python2.7/site-packages/pycassa/pool.py", line 442, in fill
conn = self._create_connection()
File "/usr/lib/python2.7/site-packages/pycassa/pool.py", line 431, in _create_connection
(exc.__class__.__name__, exc))
pycassa.pool.AllServersUnavailable: An attempt was made to connect to each of the servers twice, but none of the attempts succeeded. The last failure was TTransportException: Could not connect to localhost:9160
I am using python 2.7. 我正在使用python 2.7。 What is the problem, Any help would be appreciated. 有什么问题,任何帮助将不胜感激。
Perhaps try specifying the host: 也许尝试指定主机:
pool = ConnectionPool('Keyspace1', ['server_node_here:9160']) 池= ConnectionPool('Keyspace1',['server_node_here:9160'])
General way to connect Cassandra with python. 用Cassandra连接python的一般方法。
from cassandra.cluster import Cluster
cluster = Cluster() #for connecting on localhost
cluster = Cluster(['192.168.0.1', '192.168.0.2']) #*for connecting on clusters (comment this line, if you are connecting with localhost)*
session = cluster.connect('testing')
You can also connect using model class with python 您还可以通过python使用模型类进行连接
from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model
from cassandra.cqlengine.management import sync_table
from cassandra.cqlengine import connection
import uuid
from datetime import datetime
connection.setup(['127.0.0.1'], "testing") #testing is the keyspace
For detail information for model class implementation take a look : https://github.com/vishal-kr-yadav/NoSQL_Databases 有关模型类实现的详细信息,请查看 : https : //github.com/vishal-kr-yadav/NoSQL_Databases
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.