Jeremy G.
Jeremy G.

Reputation: 101

py2neo SocketError: Connection refused, but curl works

I'm trying to get a Flask/Neo4j app set up on a remote Ubuntu server, and I've run into a problem that I haven't been able to figure out. My app uses py2neo, but when it tries to connect to the graph, the app crashes and the Neo4j process seems to stop. I've tried connecting in a python shell like this...

test = Graph('http://localhost:7474/db/data/',username='neo4j',password='myPassword')

which fails, and also renders neo4j inoperative until I restart it. However, these return 200 responses (and the web interface also works):

curl -u neo4j http://localhost:7474/db/data/

requests.get('http://localhost:7474/db/data/', auth=('neo4j','myPassword'))

I've tried to provide more information than this similar question, because it seems like the connection works from everywhere but py2neo.

Here's the full traceback:

Traceback (most recent call last):
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/database/__init__.py", line 318, in __new__
    inst = cls.__instances[key]
KeyError: (<class 'py2neo.database.Graph'>, <ServerAddress settings={'http_port': 7474, 'host': 'localhost'}>, 'data')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 322, in submit
    response = send()
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 317, in send
    http.request(xstr(method), xstr(uri.absolute_path_reference), body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 80, in connect
    self.source_address)
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/database/__init__.py", line 327, in __new__
    use_bolt = version_tuple(inst.__remote__.get().content["neo4j_version"]) >= (3,)
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/database/http.py", line 154, in get
    response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 966, in get
    return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 943, in __get_or_head
    return rq.submit(redirect_limit=redirect_limit, **kwargs)
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 433, in submit
    http, rs = submit(self.method, uri, self.body, self.headers)
  File "/home/deploy/toponimika/toponimikaenv/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 362, in submit
    raise SocketError(code, description, host_port=uri.host_port)
py2neo.packages.httpstream.http.SocketError: Connection refused

Anything I might try to figure out what's going on would be appreciated.

Upvotes: 2

Views: 1318

Answers (2)

I had the same issue, solved with a simple upgrade of pip version.

pip install --upgrade py2neo

Upvotes: 0

J. Vinoth
J. Vinoth

Reputation: 21

Changed to http://username:password@localhost:7474/db/data/ and it works!

Example:

test = Graph('http://username:password@localhost:7474/db/data/')

Upvotes: 2

Related Questions