cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to ne04j in Vagrant/Django

MAR_DEV
Node

Newbie problem:

I'm trying to connect to NEO4J from Django/Vagrant and I keep getting a "ConnectionRefusedError: [Errno 111] Connection refused"  when I try to run neomodel_install_labels.

in my settings file I've added:

 

from neomodel import config
import os

DATABASES = {
   'default': env.db('SNAP_DATABASE_URL'),
}

#Connect to Neo4j Database
config.DATABASE_URL = os.environ["NEO4J_BOLT_URL"]

NEOMODEL_SIGNALS = True
NEOMODEL_FORCE_TIMEZONE = False
NEOMODEL_ENCRYPTED_CONNECTION = False
NEOMODEL_MAX_CONNECTION_POOL_SIZE = 50

 

 

 

In my .env.vagrant file
NEO4J_USERNAME=neo4j 
NEO4J_PASSWORD=test
NEO4J_BOLT_URL="bolt://$NEO4J_USERNAME:$NEO4J_PASSWORD@localhost:7687"

In my model file:

from neomodel import (
    config,
    StringProperty,
    StructuredNode,
    RelationshipTo,
    RelationshipFrom,
    Relationship
)

import os

config.DATABASE_URL = os.environ["NEO4J_BOLT_URL"]

I receive the error when I try to install_labels.

vagrant@ubuntu-focal:/vagrant$ pipenv run neomodel_install_labels data_api.py  data_api/models/language.py --db bolt://neo4j:test@localhost:7687

Loading .env environment variables...
Loaded data_api.py.
Loaded data_api/models/language.py.
Connecting to bolt://neo4j:test@localhost:7687

Setting up indexes and constraints...

Found language.Language
 + Creating index node_id on label Language for class language.Language
Traceback (most recent call last):
  File "/home/vagrant/.local/share/virtualenvs/vagrant-gKDsaKU3/lib/python3.9/site-packages/neo4j/_async_compat/network/_bolt_socket.py", line 504, in _connect
    s.connect(resolved_address)
ConnectionRefusedError: [Errno 111] Connection refused
3 REPLIES 3

steggy
Neo4j
Neo4j

hi @MAR_DEV,

Have you checked to make sure that neo4j is listening on localhost at port 7687 and not a different port or network interface? netstat -an | grep -i listen | grep 7687 would be one way to check that

MAR_DEV
Node

Hello 

Yes, a team member and myself both checked.  It is working outside of Vagrant.

steggy
Neo4j
Neo4j

It's been an awful long time since I've played with vagrant... Isn't there a special IP you have to use inside of Vagrant to refer to the host box's localhost? 

Edit: maybe 10.0.2.2? Found this: https://stackoverflow.com/questions/23971373/is-it-possible-to-access-a-localhost-from-a-vagrant-dev...