Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-11-2022 10:47 AM
I have a virtual machine that i can access via SSH with ssh username@ipv4. I installed neo4j there and can access localhost on the machine, but I wasn't able to connect it to my machine through SSH via python. I am able to connect to the virtual machine using sshtunnel library (example 1), but then I can't connect to Neo4j because I don't know how to obtain the URI to connect to their python driver. How can I get the URI to access the neo4j database?
Here is my code
import logging
import sshtunnel
from sshtunnel import SSHTunnelForwarder
import sys
from neo4j import GraphDatabase
ssh_host = 'xyz.xyz.xyz.xyz'
ssh_username = 'username'
ssh_password = 'password'
def open_ssh_tunnel(verbose=False):
"""Open an SSH tunnel and connect using a username and password.
:param verbose: Set to True to show logging
:return tunnel: Global SSH tunnel connection
"""
if verbose:
sshtunnel.DEFAULT_LOGLEVEL = logging.DEBUG
global tunnel
tunnel = SSHTunnelForwarder(
(ssh_host, 22),
ssh_username = ssh_username,
ssh_password = ssh_password,
remote_bind_address = ('127.0.0.1', 7687)
)
tunnel.start()
def close_ssh_tunnel():
"""Closes the SSH tunnel connection.
"""
tunnel.close
open_ssh_tunnel()
#How do i get URI? tunnel.local_bind_port does not work
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
driver.close()
close_ssh_tunnel()
All the sessions of the conference are now available online