I'm using the client.Client
class from gremlin_python.driver
to connect to AWS Neptune. See the following
def _prepare_request(method, url, *, data=None, params=None, headers=None, service='neptune-db'):
_ = requests.Session()
request = requests.Request(method=method, url=url, data=data, params=params, headers=headers)
credentials = Session().get_credentials()
frozen_creds = credentials.get_frozen_credentials()
req = AWSRequest(method=method, url=url, data=data, params=params, headers=headers)
SigV4Auth(frozen_creds, service, os.environ['AWS_REGION']).add_auth(req)
prepared_iam_req = req.prepare()
request.headers = dict(prepared_iam_req.headers)
return request.prepare()
# https
http_protocol = 'https'
uri = f'{http_protocol}://{self.host}:{self.port}/gremlin'
request = _prepare_request('GET', uri)
# wss
ws_url = 'wss://{}:{}/gremlin'.format(self.host, self.port)
ws_request = httpclient.HTTPRequest(ws_url, headers=dict(request.headers))
self.conn = client.Client(ws_request, 'g')
Now my question how can I used the client.Client object from above to get a traversal object "g".
There is a similar example at https://pypi.org/project/gremlinpython/#description showing this. But I can't use the DriverRemoteConnection in the above code.
>>> from gremlin_python.process.anonymous_traversal import traversal
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
>>> g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))