简体   繁体   English

无法将cassandra与python连接

[英]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.

相关问题 Python无法通过Docker连接到Cassandra - Python Unable to Connect to Cassandra through Docker 无法从远程计算机连接到Cassandra服务器 - Unable to connect to Cassandra server from a remote machine Cassandra cqlsh“无法连接到任何服务器” - Cassandra cqlsh “unable to connect to any servers” Python Cassandra 驱动程序:连接到服务器上的 Docker 容器 - Z121C60DF0C03083FDFB5}UnC2541Cont1. - Python Cassandra driver: connect to Docker container on server - cassandra.UnresolvableContactPoints: {} 如何将python连接到使用docker运行的cassandra - how to connect python to cassandra that run with docker 如何在 Anaconda 中的 Jupyter notebook 中使用 Python 连接 Cassandra? - How to connect Cassandra in Jupyter notebook In Anaconda with Python? Python3: cassandra.cluster.NoHostAvailable: (“Unable to connect to any servers using keyspace 'test'”, ['127.0.0.1']) when using execute_async future - Python3: cassandra.cluster.NoHostAvailable: (“Unable to connect to any servers using keyspace 'test'”, ['127.0.0.1']) when using execute_async future 无法连接MySQL和Python - Unable to connect MySQL and Python 无法将 Python 连接到 MySQL - Unable to connect Python to MySQL Python:无法连接数据库 - Python: unable connect with database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM