我在Anaconda上运行Python。我想使用python连接到cassandra,但这是我得到的错误。
macs-MacBook-Air:~ mac$ python
Python 3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cql
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mac/anaconda/lib/python3.6/site-packages/cql/__init__.py", line 17, in <module>
from cql.apivalues import *
File "/Users/mac/anaconda/lib/python3.6/site-packages/cql/apivalues.py", line 17, in <module>
import exceptions
ModuleNotFoundError: No module named 'exceptions'
>>>
修改
导入适用于Python 2,如评论中所指出的那样。
macs-MacBook-Air:~ mac$ python2
Python 2.7.13 (default, Apr 4 2017, 08:47:57)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cql
>>> con = cql.connect('xxx.xxx.xxx.xxx', 9023, 'keyspace', cql_version='3.4.2')
No handlers could be found for logger "thrift.transport.TSocket"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/cql/connection.py", line 143, in connect
consistency_level=consistency_level, transport=transport)
File "/usr/local/lib/python2.7/site-packages/cql/connection.py", line 59, in __init__
self.establish_connection()
File "/usr/local/lib/python2.7/site-packages/cql/thrifteries.py", line 151, in establish_connection
self.transport.open()
File "/usr/local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 269, in open
return self.__trans.open()
File "/usr/local/lib/python2.7/site-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 [('xxx.xxx.xxx.xxx', 9023)]
>>>
这听起来像是权限问题吗? Cassandra托管在AWS上的EC2实例上。也许,这是一个权限问题?任何建议。