Re: [TinkerPop] Connection was closed by server.

28 views
Skip to first unread message

Bernard Dudley

unread,
Dec 20, 2024, 8:37:06 AM12/20/24
to gremli...@googlegroups.com
In my experience, gremlin-python does not actually connect when this code runs: g = graph.traversal().withRemote(connection). Instead, the connection will be attempted when the first traversal is submitted. It looks to me like you never had a connection.
I'd suggest a simple query to check that you actually have a connection. We use g.inject(1).next() for this. It will return a 1 if you have a server connected.
How you debug this will depend to some extent on the nature of the server at gremlin_endpoint . What are you connecting to?

I also suggest you capture the return value of your addV traversal. You should get a node object back if you've successfully added the node. But get your connection sorted first.

On Tue, 10 Dec 2024 at 18:40, shayne williams <shaynew...@worknest.com> wrote:
I am trying to ingest a dataframe using gremlin-python but keep getting the same error: 
I don't seem to be able to get even one row in before the connection is disconnected by the servers. I'm using  gremlinpython==3.6.2 and python 3.10.12
graph = Graph()
connection = DriverRemoteConnection(
    gremlin_endpoint, "g",
    username=gremlin_username,
    password=gremlin_password
)
g = graph.traversal().withRemote(connection)

def upload_node(row):
    try:
        # Extract values as strings to ensure scalar access
        label = row['label'] if 'label' in row and pd.notnull(row['label']) else None
        node_id = row['id'] if 'id' in row and pd.notnull(row['id']) else None
        partition_key = row['Key'] if 'Key' in row and pd.notnull(row['Key']) else None

        print(label, node_id, partition_key)

        # Check for missing mandatory fields
        if not label or not node_id or not partition_key:
            print(f"Skipping row with missing values: label={label}, id={node_id}, Key={partition_key}")
            return

        # Create Gremlin vertex
        g.addV(str(label)).property('id', str(node_id)).property('PartitionKey', str(partition_key)).next()
       

        print(f"Node {node_id} uploaded successfully.")
    except Exception as e:
        print(f"Error uploading node {node_id if 'node_id' in locals() else 'unknown'}: {e}")




try:
    print("Starting node upload...")
    for _, row in df_client_pand100.iterrows():  # Iterate over rows
        upload_node(row)
except Exception as e:
    print(f"Unexpected error: {e}")
finally:
    connection.close()
    print("Node upload process complete.")

OUTPUT:
Starting node upload... Client CL_182591 79 Error uploading node CL_182591: Connection was closed by server. Node upload process complete.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/gremlin-users/f0c5aeed-b966-4341-a367-e2676fec7cbcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages