1

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.

4
  • 1
    I suspect 0.0.0.0 should be a real IP? Commented Nov 6, 2018 at 13:59
  • you are correct. in this sample code, I did not put correct IP. I have updated the IP Commented Nov 7, 2018 at 7:58
  • 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? Commented Nov 8, 2018 at 16:07
  • @RebeccaNelson, all were on the same server. and this question has been answered in detail here ->:stackoverflow.com/questions/53185602/… Thanks for your time. Commented Nov 9, 2018 at 1:41

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@Servesh Have you tried changing 'g' in your code to something else, such as 'graph'?
@ServeshSingh I see the code in the question. My point was that, as with any database technology, you would specify what you are connecting to during some configuration after a URI (the websocket, in your case). The most obvious place to me seems like simply renaming 'g' ==> 'graph'. You don't need to follow the documentation examples exactly, they are only meant to show the syntax. And all I did was ask if you tried
@ServeshSingh I defer to Rebecca here to answer your initial question. Or your new one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.