【问题标题】:missing key `scheme` error while doing graph.run() in Neo4j在 Neo4j 中执行 graph.run() 时缺少键“方案”错误
【发布时间】:2017-05-08 08:23:04
【问题描述】:

这是我的py2neo 代码,用于从 txt 文件创建图表:

import csv
import re
from py2neo import Graph,Node,Relationship
graph = Graph("http://localhost:7474/browser/")
with open("<>") as infile:
    row_num = 0
    for row in infile:
        row1 = re.split(r'\s{2,}', row[6:13])
        row2 = re.split(r'\s{2,}', row[16:76])
        #print len(row2[0]),row2[0]
        if(row_num<1000):
            x = len(row1[0])
            code = Node("Dis_code", Code=row1[0])
            valid = Node("Valid", Valid=row[14])
            name = Node("Name_dis", Name=row2[0])
            code_is_valid = Relationship(code,"valid or not",valid)
            code_name= Relationship(code, "has name", name)
            #x=len(row1[0])
            print x
            parent = []
            if (x>3):
                row_num = row_num + 1
                print row1[0][:-1]
                for cod in graph.run("MATCH (p:Dis_code{Code:row1[0][:-1]}) RETURN p"):
                    print cod
                    code_parent = Relationship(code,"has_parent",cod)

我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/<>/PycharmProjects/graph/data_model", line 24, in <module>
    for cod in graph.run("MATCH (p:Dis_code{Code:row1[0][:-1]}) RETURN p"):
  File "C:\Python27\lib\site-packages\py2neo-4.0.0b2-py2.7.egg\py2neo\graph.py", line 654, in run
    return self.begin(autocommit=True).run(statement, parameters, **kwparameters)
  File "C:\Python27\lib\site-packages\py2neo-4.0.0b2-py2.7.egg\py2neo\graph.py", line 380, in begin
    return Transaction(self, autocommit)
  File "C:\Python27\lib\site-packages\py2neo-4.0.0b2-py2.7.egg\py2neo\graph.py", line 804, in __init__
    self.session = driver.session()
  File "build\bdist.win32\egg\neo4j\v1\bolt.py", line 54, in session
neo4j.v1.security.Unauthorized: Unsupported authentication token, missing key `scheme`

我在run module's documentation 中没有找到任何名为scheme 的内容。那么,我这里哪里出错了?

【问题讨论】:

  • 只是检查一下(我不是 py2neo 的专家),但你有正确的 URL (localhost:7474/browser) 吗?您可以尝试仅使用 Graph() ... 因为您似乎想连接到 localhost 数据库?
  • 是的,URL 是正确的,我也尝试使用 Graph(),但我得到了同样的错误
  • 很公平。您可以尝试一下:from py2neo import Graph,Node,Relationship graph = Graph("localhost:7474/browser/") 如果这也不起作用,您可以在其中添加数据库的用户名密码组合吗:from py2neo import Graph,Node ,Relationship graph = Graph("http://:@localhost:7474/browser/") ... 只需这两行,我们就可以确定问题出在身份验证还是其他部分你的代码

标签: python neo4j py2neo


【解决方案1】:

“缺少钥匙”消息在技术上是正确的,但在这里对您没有帮助。给出线索的错误部分是“neo4j.v1.security.Unauthorized”。出于某种原因,您尝试访问浏览器应用程序 URI (http://localhost:7474/browser/) 而不是实际的数据库 URI (http://localhost:7474/db/data/)。您也没有提供任何凭据。您在这里实际需要的是:

graph = Graph("http://localhost:7474/db/data/", user="neo4j", password="s3cr3t!")

(当然要为您的服务器使用正确的密码。)

Graph 构造函数的详细信息可以在这里找到 -> http://py2neo.org/v3/database.html#the-graph

【讨论】:

    猜你喜欢
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多