Servesh Singh
Servesh Singh

Reputation: 113

How to connect with an existing JanusGraph using Gremlin-Python

I have created a graph with a set of vertices and edges in JanusGraph using Gremlin console. I want to open the same graph and want to add more vertices using Gremlin-Python.

I have written below code, but it is not working and it gives me zero vertices.

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
statics.load_statics(globals());   
graph = Graph()
remote_connection = DriverRemoteConnection('ws://localhost:8182/gremlin','g');
g = graph.traversal().withRemote(remote_connection);
print(g)
print (g.V().count().next());

I don't know how to connect with the existing graph "mygraph" using Gremlin-Python? I don't want to create new graph here.

Upvotes: 1

Views: 594

Answers (1)

Rebecca Nelson
Rebecca Nelson

Reputation: 1296

As mentioned in comments by @cricket_007, "0.0.0.0" will resolve to the IP address of the server that your python app is on. You need to update your connection string to point to the server that your Gremlin Server is running on.

In general, this will be the server that your instance of JanusGraph is on. For instance, if the external IP of the JanusGraph server is "10.167.12.195", you should change your connection string to ws://10.167.12.195:8182/gremlin.

Upvotes: 4

Related Questions