Neo4j Python py2neo authorization error

若如初见. 提交于 2019-12-10 10:16:02

问题


Installed Neo4j 2.2.3 on Windows 8.1. Nothing special. Started the server through the Neo4j start app. Nothing special Started working with py2neo as in the documentation on Neo4j.org. Ran into an authorization error I cannot explain. Log follows below.

One special remark: in spite of python\script being in the path the python shell will only start from C:\python34\python.

Please explain what I'm doing wrong and can improve.

The Log:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle rechten voorbehouden.

C:\Users\Fred>c:\Python34\python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from py2neo import Graph
>>> graph = Graph()
>>> from py2neo import Node, Relationship
>>> Z1 = Node("Zoeker", naam="Zoeker 1")
>>> O1 = Node("Opleiding", naam="Opleiding 1")
>>> Z1_heeft_O1 = Relationship(Z1, "heeft", O1)
>>> graph.create(Z1_heeft_O1)
Traceback (most recent call last):
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 258, in get response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
  File "c:\Python34\lib\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 "c:\Python34\lib\site-packages\py2neo\packages\httpstream\http.py", line 943, in __get_or_head return rq.submit(redirect_limit=redirect_limit, **kwargs)
  File "c:\Python34\lib\site-packages\py2neo\packages\httpstream\http.py", line 452, in submit return Response.wrap(http, uri, self, rs, **response_kwargs)
  File "c:\Python34\lib\site-packages\py2neo\packages\httpstream\http.py", line 489, in wrap raise inst 
py2neo.packages.httpstream.http.ClientError: 401 Unauthorized

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 712, in create statement = CreateStatement(self)
  File "c:\Python34\lib\site-packages\py2neo\cypher\create.py", line 44, in __init__ self.supports_node_labels = self.graph.supports_node_labels
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 1086, in supports_node_labels return self.neo4j_version >= (2, 0)
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 964, in neo4j_version return version_tuple(self.resource.metadata["neo4j_version"])
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 213, in metadata self.get()
  File "c:\Python34\lib\site-packages\py2neo\core.py", line 261, in get raise Unauthorized(self.uri.string)
py2neo.error.Unauthorized: http://localhost:7474/db/data/
>>>

回答1:


neo4j 2.2 introduced authentication which is enabled by default. When you open the webinterface (usually http://localhost:7474/browser) for the first time, you will be asked to set a username/password. The default is neo4j/neo4j.

Here is how to use authentication in py2neo:

from py2neo import authenticate, Graph

# set up authentication parameters
authenticate("camelot:7474", "arthur", "excalibur")

# connect to authenticated graph database
graph = Graph("http://camelot:7474/db/data/")

See: http://py2neo.org/2.0/essentials.html#py2neo.authenticate




回答2:


In my case, this worked.

Under libexec/conf, find the neo4j.conf folder.

Delete the # before the "dbms.security.auth_enabled=false"



来源:https://stackoverflow.com/questions/31093419/neo4j-python-py2neo-authorization-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!