AWS beanstalk 中的 Flask 应用程序 运行 无法连接到远程 cassandra

Flask app running in AWS beanstalk not able to connect to remote cassandra

我正在 运行在 aws beantalk 上安装一个 python(3.4) flask 应用程序。当我登录到 ec2 shell 并尝试在本地 运行 flask 应用程序时,它 运行 正确并轻松地从远程 cassandra 获取数据。但是在从 cassandra 获取数据时,AWS eb 的应用 运行 不断在 httpd/error_log 中抛出以下错误。

ERROR in app: Exception on /user/1003 [GET]
Traceback (most recent call last):
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/python/current/app/application.py", line 53, in user_profile
data = get_user_data(id)
File "/opt/python/current/app/application.py", line 163, in get_user_data
if obj:
File "/opt/python/run/venv/lib64/python3.4/site-packages/cassandra/cqlengine/query.py", line 393, in __le
n__
self._execute_query()
File "/opt/python/run/venv/lib64/python3.4/site-packages/cassandra/cqlengine/query.py", line 428, in _exe
cute_query
self._result_generator = (i for i in self._execute(self._select_query()))
File "/opt/python/run/venv/lib64/python3.4/site-packages/cassandra/cqlengine/query.py", line 360, in _exe
cute
result = _execute_statement(self.model, statement, self._consistency, self._timeout)
File "/opt/python/run/venv/lib64/python3.4/site-packages/cassandra/cqlengine/query.py", line 1412, in _ex
ecute_statement
parts = model._routing_key_from_values(key_values, connection.get_cluster().protocol_version)
File "/opt/python/run/venv/lib64/python3.4/site-packages/cassandra/cqlengine/connection.py", line 183, in
 get_cluster
raise CQLEngineException("%s.cluster is not configured. Call one of the setup or default functions firs
t." % __name__)
cassandra.cqlengine.CQLEngineException: cassandra.cqlengine.connection.cluster is not configured. Call one
of the setup or default functions first.

我的环境:

(venv)[ec2-user@ip-11.1.1.1 ~]$ pip freeze
cassandra-driver==3.6.0
click==6.6
Cython==0.24.1
Flask==0.11
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
six==1.10.0
Werkzeug==0.11.11
xmltodict==0.10.2 

此致

您没有先设置与 Cassandra 的连接。您需要先执行此操作,然后才能对其执行查询。