Python Django: Minimal Local Django + Cassandra Application

I am trying to put together a minimal Django application that uses Cassandra as its database.

Here's what I've tried:

  • Created a new Django project in PyCharm. Make sure it python manage.py runserver

    works as expected .
  • Installed Cassandra using instructions here . I had to change rpc_port

    and storage_port

    to the numbers below 9000 to get it to work (maybe that has something to do with my firewall). Cassandra works and I can follow instructions with cqlsh

    .
  • Installed cassandra-django-engine

    .
  • Made the following changes to the file settings.py

    :

    • Added django_cassandra_engine

      to the beginning of the tuple INSTALLED_APPS

      :

      INSTALLED_APPS = (
      'django_cassandra_engine',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      )
      
            

    • Replaced SQLite as database with Cassandra, for example:

      DATABASES = {
         'default': {
           'ENGINE': 'django_cassandra_engine',
           'NAME': 'db',
           'TEST_NAME': 'test_db',
           'HOST': 'localhost',
           'PORT': '8160',
           'OPTIONS': {
             'replication': {
             'strategy_class': 'SimpleStrategy',
             'replication_factor': 1
            }
          }
        }
      } 
      
            

      Please note that this is the part I'm not sure about. I couldn't figure out, based on the documentation, what the parameters NAME

      and should be TEST_NAME

      . Note also that I added a key 'PORT'

      and that the default port number is 9160

      , but I changed it to 8160

      for the reasons mentioned above. Not sure if I need to add this key.

Error information:

Below is the full error response when starting python manage.py runserver

with the above project. Please note: there are no applications in the project yet.

/usr/local/lib/python3.4/dist-packages/django/db/utils.py:238: RemovedInDjango19Warning: In Django 1.9 the TEST_NAME connection setting will be moved to a NAME entry in the TEST setting
  self.prepare_test_settings(alias)

/usr/local/lib/python3.4/dist-packages/cassandra/util.py:486: UserWarning: The blist library is not available, so a pure python list-based set will be used in place of blist.sortedset for set collection values. You can find the blist library here: https://pypi.python.org/pypi/blist/
  "The blist library is not available, so a pure python list-based set will "

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/models.py", line 7, in <module>
    from uwsgidecorators import postfork
  File "/usr/local/lib/python3.4/dist-packages/uwsgidecorators.py", line 10, in <module>
    import uwsgi
ImportError: No module named 'uwsgi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/models.py", line 12, in <module>
    cassandra_connection.connect()
  File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/base/__init__.py", line 94, in connect
    self.connection = CassandraConnection(**settings)
  File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/connection.py", line 52, in __init__
    self.setup()
  File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/connection.py", line 59, in setup
    connection.setup(self.hosts, self.keyspace, **self.connection_options)
  File "/usr/local/lib/python3.4/dist-packages/cassandra/cqlengine/connection.py", line 129, in setup
    session = cluster.connect()
  File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 755, in connect
    self.control_connection.connect()
  File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 1868, in connect
    self._set_new_connection(self._reconnect_internal())
  File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 1903, in _reconnect_internal
    raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'localhost': OperationTimedOut('errors=None, last_host=None',)})

      

From what I can understand
1. There is an upper level ImportError

:

ImportError: No module named 'uwsgi'

      

2. And there is a nested error:

cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'localhost': OperationTimedOut('errors=None, last_host=None',)})

      

I'm not sure which of the two above is the more relevant error and how to resolve the error anyway. Please note that I have installed both modules uwsgi

and uwsgidecorators

.

+3


source to share


1 answer


So it turns out that the answer was pretty simple. Yes, a key is required 'PORT'

(actually a key 'PORT'

), but it goes into the setting 'connection'

and is set to storage_port

, not to rpc_port

. After making these changes, the Django server is running cleanly.



0


source







All Articles