Closed scheung38 closed 8 years ago
I think that's a modeling issue. The days should be stored as a property, not as a part of the relationship type. Then you could query for just the :DAYS
relationship type and do manipulations with the property on that relationship.
Could you give simple example? Thanks
Also noticed that starting:
from py2neo import Graph
graph = Graph()
.bashrc: export NEO4J_USERNAME=neo4j export NEO4J_PASSWORD=mypassword
and even after changing /usr/local/Cellar/neo4j/2.2.5/libexec/conf: dbms.security.auth_enabled=false
http://localhost:7474/db/data/ still returns
{
errors: [
{
code: "Neo.ClientError.Security.AuthorizationFailed",
message: "No authorization header supplied."
}
]
}
I'm not sure what methods you are using in the code you included. But with py2neo, you can set relationship properties like so:
from py2neo import Graph, Node, Relationship
graph = Graph()
buenos_aires = Node("Port", name="Buenos Aires")
new_york = Node("Port", name="New York")
casablanca = Node("Port", name= "Casablanca")
cape_town = Node("Port", name="Cape Town")
graph.create(buenos_aires, new_york, casablanca, cape_town)
rel1 = Relationship(buenos_aires, "TRIP_TO", new_york, days=6)
rel2 = Relationship(buenos_aires, "TRIP_TO", casablanca, days=5)
rel3 = Relationship(buenos_aires, "TRIP_TO", cape_town, days=4)
graph.create(rel1, rel2, rel3)
Using:
python 2.7.10 py2neo 2.0.8
with the above settings, but running example as it is:
Traceback (most recent call last):
File "/Users/seb/PycharmProjects/Neo4jSample/sample_py2neo.py", line 9, in <module>
graph.create(buenos_aires, new_york, casablanca, cape_town)
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/core.py", line 706, in create
statement = CreateStatement(self)
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/cypher/create.py", line 44, in __init__
self.supports_node_labels = self.graph.supports_node_labels
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/core.py", line 1080, in supports_node_labels
return self.neo4j_version >= (2, 0)
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/core.py", line 958, in neo4j_version
return version_tuple(self.resource.metadata["neo4j_version"])
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/core.py", line 213, in metadata
self.get()
File "/Users/seb/anaconda/envs/pyenv2.7.10/lib/python2.7/site-packages/py2neo/core.py", line 261, in get
raise Unauthorized(self.uri.string)
py2neo.error.Unauthorized: http://localhost:7474/db/data/
You need to authenticate or turn off authentication.
But the conf already took care of that when I changed auth_enabled=false :
/usr/local/Cellar/neo4j/2.2.5/libexec/conf:
dbms.security.auth_enabled=false
or is it the case that this installation was done via brew install neo4j and this conf file was not read in?
Can you try using a version of Neo4j that wasn't installed with brew?
Does it make a difference actually? Since neo4j is running in the background and localhost:7474 takes user to neo4j dashboard. it is the database that cannot be authorized for some reason. I see that in your models.py example
import os
url = os.environ.get('GRAPHENEDB_URL', 'http://localhost:7474')
username = os.environ.get('NEO4J_USERNAME')
password = os.environ.get('NEO4J_PASSWORD')
if username and password:
authenticate(url.strip('http://'), username, password)
graph = Graph(url + '/db/data/')
But still same error.
I think it must make a difference. If setting dbms.security.auth_enabled=false
didn't work, I think you should try with a version of Neo4j that was installed normally.
Before doing reinstallation,
this conf in my case:
/usr/local/Cellar/neo4j/2.2.5/libexec/conf:
dbms.security.auth_enabled=false
But project is in
/Users/seb/PycharmProjects/SampleNeo4j/models.py
is there anyway to read in within python to check its status? It is a bit strange to have conf file in totally different path, relative to user application path...
It shouldn't matter. Maybe try hardcoding in the username and password to make sure it's not just an environment variable problem:
url = "http://localhost:7474"
username = "your_username"
password = "your_password"
authenticate(url.strip('http://'), username, password)
graph = Graph(url + "/db/data/")
url = os.environ.get('GRAPHENEDB_URL', 'http://localhost:7474') -> url: 'http://localhost:7474'
username = os.environ.get('NEO4J_USERNAME') -> username: 'neo4j'
password = os.environ.get('NEO4J_PASSWORD') -> password: 'mypassword'
if username and password:
authenticate(url.strip('http://'), username, password)
graph = Graph(url + '/db/data/') -> graph : <Graph uri= u'http://localhost:7474/db/data/'>
so it seems like it is passing through the if username and password comparison and the other values are read in from .bashrc where I set NEO4J_USERNAME and NEO4J_PASSWORD.
That's why I suggested hardcoding the values to check if it was an environment variable problem. Does it work if you set the values in the code as I suggested?
So with the returned values above I can access dashboard
http://localhost:7474
But
http://localhost:7474/db/data/
still returns:
{
errors: [
{
code: "Neo.ClientError.Security.AuthorizationFailed",
message: "No authorization header supplied."
}
]
}
which means something is still incorrect as no data generated along with the above message?
What is "the dashboard"?
Single stepping seem to be fine as each step is returning some value, until the last
graph.create(rel1, rel2, rel3, ..)
upon executing I get a
Frame is not available
Sorry when referring to the dashboard, I simply meant the localhost:7474/browser page from Neo4j
That code snippet works fine for me. I'd check your syntax or run it all at once.
and what did you get when you to go http://localhost:7474/db/data/? thanks
This is what I have:
from py2neo import Graph, Node, Relationship, authenticate
import os
url = os.environ.get('GRAPHENEDB_URL', 'http://localhost:7474')
username = os.environ.get('NEO4J_USERNAME')
password = os.environ.get('NEO4J_PASSWORD')
if username and password:
authenticate(url.strip('http://'), username, password)
graph = Graph(url + '/db/data/')
buenos_aires = Node("Port", name="Buenos Aires")
new_york = Node("Port", name="New York")
liverpool = Node("Port", name="Liverpool")
casablanca = Node("Port", name="Casablanca")
cape_town = Node("Port", name="Cape Town")
graph.create(buenos_aires, new_york, liverpool, casablanca, cape_town)
rel1 = Relationship(buenos_aires, "TRIP_TO", new_york, days=6)
rel2 = Relationship(buenos_aires, "TRIP_TO", casablanca, days=5)
rel3 = Relationship(buenos_aires, "TRIP_TO", cape_town, days=4)
rel4 = Relationship(new_york, "TRIP_TO", liverpool, days=4)
rel5 = Relationship(liverpool, "TRIP_TO", casablanca, days=3)
rel6 = Relationship(liverpool, "TRIP_TO", cape_town, days=6)
rel7 = Relationship(casablanca, "TRIP_TO", liverpool, days=3)
rel8 = Relationship(casablanca, "TRIP_TO", cape_town, days=6)
rel9 = Relationship(cape_town, "TRIP_TO", new_york, days=8)
graph.create(rel1, rel2, rel3, rel4, rel5, rel6, rel7, rel8, rel9)
print 'Hello'
but end result at http://localhost:7474/db/data/:
Try doing these one at a time:
graph.create(Relationship(buenos_aires, "TRIP_TO", new_york, days=6))
graph.create(Relationship(buenos_aires, "TRIP_TO", casablanca, days=5))
graph.create(Relationship(buenos_aires, "TRIP_TO", cape_town, days=4))
...
same message at http://localhost:7474/db/data/
what is displayed at your end when you view http://localhost:7474/db/data/?
This is not related to the browser. Please install Neo4j regularly (not through Homebrew) and try again.
OK with clean install now works!
uninstalled brew version
But not sure why browser shows the same graph 4x?
Modified graph in python, but neo4j still showing previous old graph data even with browser page reload? How do we migrate or delete db? Normally Pycharm can delete dB within project, but not sure how to delete here as db is not stored in application directory? Other than knowing the url for database is
http://localhost:7474/db/data
rm -rf graph.db the way currently to delete, but chrome browser still rendering old graph?
From doc I can understand this syntax of finding movies that match a certain pattern and returning it
MATCH (m:Movie) WHERE m.title = "The Matrix" RETURN m
But more useful queries I like to learn how to perform would be like:
Not sure how to go about it as I may have to dug deep into doc for these queries. Does example also show unittesting? Any guidance would be appreciated.
I was happy to help you get up and running with py2neo, but your questions are now beyond the scope of this project. You should consider posting them to StackOverflow.
Hi Nicole,
I am trying to do this:
then how to do the query as each relationship is not the same as generic ‘LIKE’ but different number of days?
say needing to find out number of days from New York to Liverpool to Cape Town etc?