Question

I am working on django project that uses neo4j database.this is a section of my models.py file:

models.py:

from neo4django.db import models

class User(models.NodeModel):

    firstName = models.StringProperty(max_length=20)
    lastName = models.StringProperty(max_length=20)
    password = models.StringProperty(max_length=50)
    email = models.EmailProperty()
    status = models.BooleanProperty()
    BirthDate = models.DateProperty()
    gender = models.BooleanProperty()

and i follow the neo4django docs and change settings.py file: setting.py:

DATABASES = {
    'default': {
         'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
         'NAME': 'mylifetime',                      # Or path to database file if using sqlite3.
         # The following settings are not used with sqlite3:
         'USER': 'root',
         'PASSWORD': 'password',
         'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

NEO4J_DATABASES = {
    'default' : {
        'HOST':'localhost',
        'PORT':7474,
        'ENDPOINT':'/db/data'
    }
}

but when i run shell for create some nodes in db i get the connection refused error:

mojtaba@mojtaba-desktop:~/Documents/mylifetime$ python manage.py shell
Python 2.7.3 (default, Aug  1 2012, 05:16:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from social.models import *
>>> test = User.objects.create(firstName = 'peter' )
    Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/manager.py", line 43, in create
    return self.get_query_set().create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/query.py", line 1296, in create
    return super(NodeQuerySet, self).create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 402, in create
    obj.save(force_insert=True, using=self.db)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 315, in save
    return super(NodeModel, self).save(using=using, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 546, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 331, in save_base
    self._save_neo4j_node(using)
  File "<string>", line 2, in _save_neo4j_node
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 93, in trans_method
    len(connections[args[0].using]._transactions) < 1:
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/utils.py", line 494, in __getitem__
    conn = Client('http://%s:%d/db/data' % (db['HOST'], db['PORT']), **db['OPTIONS'])
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/neo4jclient.py", line 30, in __init__
    super(EnhancedGraphDatabase, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/client.py", line 84, in __init__
    response, content = Request(**self._auth).get(self.url)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/request.py", line 144, in get
    return self._request('GET', url, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/__init__.py", line 61, in _request
    headers)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/request.py", line 306, in _request
    body=body)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1444, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1196, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1132, in _conn_request
    conn.connect()
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 798, in connect
    raise socket.error, msg
error: [Errno 111] Connection refused
Était-ce utile?

La solution

Seems a connection error. Are you sure the neo server is listening on port 7474 on localhost?

Since is rest, try with your browser on localhost:7474

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top