2

This is my py2neo code for creating a graph from a txt file:

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)

I get the following error:

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`

I didn't find anything called scheme in the run module's documentation. So, where did I go wrong here?

  • Just checking (I'm not a specialist on py2neo), but do you have the correct URL (http://localhost:7474/browser/) there ? Can you try with just Graph() ... as you seem to want to connect to the localhost database ? – Tom Geudens May 08 '17 at 08:36
  • Yeah the URL is correct and I tried with Graph() as well but I am getting the same error – Swapnil Kumar May 08 '17 at 08:41
  • Fair enough. Can you just try : from py2neo import Graph,Node,Relationship graph = Graph("http://localhost:7474/browser/") and if that also doesn't work, can you add the username password combination for your database in there : from py2neo import Graph,Node,Relationship graph = Graph("http://:@localhost:7474/browser/") ... with just those two lines we can determine if the issue is with the authentication or with another part of your code – Tom Geudens May 08 '17 at 08:52

1 Answers1

0

The "missing key" message is technically correct but unhelpful for you here. The part of the error that is giving the clue is "neo4j.v1.security.Unauthorized". For some reason, you're trying to access the browser application URI (http://localhost:7474/browser/) instead of the actual database URI (http://localhost:7474/db/data/). You're also not supplying any credentials. What you actually need here is something like:

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

(Use of course the correct password for your server.)

Details of the Graph constructor can be found here -> http://py2neo.org/v3/database.html#the-graph

Nigel Small
  • 4,475
  • 1
  • 17
  • 15