I wrote the following python code to neo4j using py2neo
JavaScript
x
8
1
from py2neo import Graph
2
from py2neo import neo4j,Node,Relationship
3
sgraph = Graph()
4
alice = Node("person",name="alice")
5
bob = Node("person",name="bob")
6
alice_knows_bob = Relationship(alice,"KNOWS",bob)
7
sgraph.create(alice_knows_bob)
8
but i got the following error
JavaScript
1
37
37
1
Traceback (most recent call last):
2
File "C:Python34libsite-packagespy2neocore.py", line 258, in get
3
response = self.__base.get(headers=headers, redirect_limit=redirect_limit, *
4
*kwargs)
5
File "C:Python34libsite-packagespy2neopackageshttpstreamhttp.py",line
6
966, in get
7
return self.__get_or_head("GET", if_modified_since, headers, redirect_limit,
8
**kwargs)
9
File "C:Python34libsite-packagespy2neopackageshttpstreamhttp.py",line
10
943, in __get_or_head
11
return rq.submit(redirect_limit=redirect_limit, **kwargs)
12
File "C:Python34libsite-packagespy2neopackageshttpstreamhttp.py",line
13
452, in submit
14
return Response.wrap(http, uri, self, rs, **response_kwargs)
15
File "C:Python34libsite-packagespy2neopackageshttpstreamhttp.py",line
16
489, in wrap
17
raise inst
18
py2neo.packages.httpstream.http.ClientError: 401 Unauthorized
19
20
During handling of the above exception, another exception occurr ed:
21
22
Traceback (most recent call last):
23
File "neo.py", line 7, in <module>
24
sgraph.create(alice_knows_bob)
25
File "C:Python34libsite-packagespy2neocore.py", line 704, in create
26
statement = CreateStatement(self)
27
File "C:Python34libsite-packagespy2neocyphercreate.py", 44,in__init__
28
self.supports_node_labels = self.graph.supports_node_labels
29
File "C:Python34libsite-packagespy2neocore.py", line 1078, in supports_node_labels return self.neo4j_version >= (2, 0)
30
File "C:Python34libsite-packagespy2neocore.py", line 956, in neo4j_version
31
return version_tuple(self.resource.metadata["neo4j_version"])
32
File "C:Python34libsite-packagespy2neocore.py", line 213, in metadata
33
self.get()
34
File "C:Python34libsite-packagespy2neocore.py", line 261, in get
35
raise Unauthorized(self.uri.string)
36
py2neo.error.Unauthorized: http://localhost:7474/db/data/
37
can anyone please help me.This is the first time i writing python code to connect to neo4j.
Advertisement
Answer
If you’re using Neo4j 2.2, authentication for database servers is enabled by default. You need to authenticate before performing further operations. Read documentation.
JavaScript
1
11
11
1
from py2neo import authenticate, Graph
2
3
# set up authentication parameters
4
authenticate("localhost:7474", "user", "pass")
5
6
# connect to authenticated graph database
7
sgraph = Graph("http://localhost:7474/db/data/")
8
9
# create alice and bob
10
11
From the same documentation,
Py2neo provides a command line tool to help with changing user passwords as well as checking whether a password change is required.
For a new installation, use:
JavaScript
1
3
1
$ neoauth neo4j neo4j my-p4ssword
2
Password change succeeded
3
After a password has been set, the tool can also be used to validate credentials
JavaScript
1
3
1
$ neoauth neo4j my-p4ssword
2
Password change not required
3