1
votes

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.

1
I suspect 0.0.0.0 should be a real IP?OneCricketeer
you are correct. in this sample code, I did not put correct IP. I have updated the IPServesh Singh
Okay, I'm still not clear on the IP address issue here. Does the app that contains the code that you have posted here reside on the same server as the JanusGraph server? Or is it being run from a different host? And if it is NOT on the same server, are you using the actual phrase localhost in your connection string? Or are you replacing localhost with the IP address of the Janus server?Rebecca Nelson
@RebeccaNelson, all were on the same server. and this question has been answered in detail here ->:stackoverflow.com/questions/53185602/… Thanks for your time.Servesh Singh

1 Answers

4
votes

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.