Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython-cypher in Python: cypher.run.Connection object parameter

I'm trying to use ipython-cypher to run Neo4j Cypher queries (and return a Pandas dataframe) in a Python program. I have no trouble forming a connection and running a query when using IPython Notebook, but when I try to run the same query outside of IPython, as per the documentation:

http://ipython-cypher.readthedocs.org/en/latest/introduction.html#usage-out-of-ipython

import cypher

results = cypher.run("MATCH (n)--(m) RETURN n.username, count(m) as neighbors", 
          "http://XXX.XXX.X.XXX:xxxx")

I get the following error: neo4jrestclient.exceptions.StatusException: Code [401]: Unauthorized. No permission -- see authorization schemes. Authorization Required

and

Format: (http|https)://username:password@hostname:port/db/name, or one of dict_keys([])

Now, I was just guessing that that was how I should enter a Connection object as the last parameter, because I couldn't find any additional documentation explaining how to connect to a remote host using Python, and in IPython, I am able to do:

%load_ext cypher
results = %cypher http://XXX.XXX.X.XXX:xxxx MATCH (n)--(m) RETURN n.username, 
count(m) as neighbors

Any insight would be greatly appreciated. Thank you.

like image 568
jgloves Avatar asked Jun 04 '26 12:06

jgloves


1 Answers

The documentation has a section for the API. When used outside of IPython and in need to connect to a different host, just using the parameter conn and passing a string should work.

import cypher

results = cypher.run("MATCH (n)--(m) RETURN n.username, count(m) as   neighbors",
                     conn="http://XXX.XXX.X.XXX:xxxx")

But also consider that with the new authentication support in Neo4j 2.2, you need to set the new password before connecting from ipython-cypher. I will fix this as soon as I implement the forcing password change mechanism in neo4jrestclient, the library underneath.

like image 200
Javier de la Rosa Avatar answered Jun 06 '26 02:06

Javier de la Rosa