【问题标题】:Python/Neptune: getting a traversal objectPython/Neptune:获取遍历对象
【发布时间】:2021-10-20 16:35:24
【问题描述】:

我正在使用来自 gremlin_python.driverclient.Client 类连接到 AWS Neptune。见下文

    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')

现在我的问题是如何使用上面的 client.Client 对象来获取遍历对象“g”。

https://pypi.org/project/gremlinpython/#description 有一个类似的例子显示了这一点。但是我不能在上面的代码中使用DriverRemoteConnection。

>>> 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'))

【问题讨论】:

标签: python amazon-web-services gremlin amazon-neptune


【解决方案1】:

添加答案以防其他人发现此讨论。

在使用 Python 处理 Amazon Neptune 时,here 有一组不错的开源实用程序,可以轻松创建 SigV4 签名请求并执行许多其他常见任务。

其中一些示例也适用于任何 Gremlin 服务器,而不仅仅是 Neptune。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多