繁体   English   中英

无法将cassandra与python连接

[英]Unable to connect cassandra with python

我正在尝试从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

我正在使用python 2.7。 有什么问题,任何帮助将不胜感激。

也许尝试指定主机:

池= ConnectionPool('Keyspace1',['server_node_here:9160'])

用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')

您还可以通过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

有关模型类实现的详细信息,请查看https : //github.com/vishal-kr-yadav/NoSQL_Databases

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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