首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Amazon提交查询: AttributeError:'str‘对象没有属性'source_instructions’

Amazon提交查询: AttributeError:'str‘对象没有属性'source_instructions’
EN

Stack Overflow用户
提问于 2021-12-17 21:20:16
回答 2查看 227关注 0票数 1

我在AWS上运行了下面的代码,但是得到了以下错误。

错误

代码语言:javascript
复制
[ERROR] AttributeError: 'str' object has no attribute 'source_instructions'
Traceback (most recent call last):

    File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 56, in submit
        result_set = self._client.submit(bytecode, request_options=self._extract_request_options(bytecode))
      File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 81, in _extract_request_options
        options_strategy = next((x for x in bytecode.source_instructionsEND RequestId: 4ee8073c-e941-43b3-8014-8717893b3188

源代码

代码语言:javascript
复制
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection


def test_neptune(host):
    remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))

    query = "g.V().groupCount().by(label).unfold().project('label','count').by(keys).by(values)"
    response = remoteConn.submit(query)
    print("response-> {}" .format(response))

    # iterate repsonse
    # go thru label
    for set_item in response:
        for item in set_item:
            print("item-> item: {}".format(item))

    remoteConn.close()

test_neptune()
EN

回答 2

Stack Overflow用户

发布于 2021-12-19 00:28:05

如果以文本字符串的形式发送查询,则需要以不同的方式创建Client对象,或者将查询写成一行Python。在(1)和(2)处有两个示例显示每个选项。您所看到的错误是因为服务器试图在发送的数据包中找到Gremlin字节码,但只找到一个字符串(该字符串没有source_instructions方法)。

使用DriverRemoteConnection,您可以使用Python代码行,如:

代码语言:javascript
复制
result = (g.V().groupCount().
                  by(label).
            unfold().
            project('label','count').
              by(keys).
              by(values).
            next())

如果您确实希望/需要将查询发送为字符串而不是字节码,请参阅我对this question的答复。

  1. https://github.com/krlawrence/graph/blob/master/sample-code/basic-client.py
  2. https://github.com/krlawrence/graph/blob/master/sample-code/glv-client.py
票数 0
EN

Stack Overflow用户

发布于 2021-12-19 00:29:41

你的DriverRemoteConnection电话错了。你有:

代码语言:javascript
复制
    remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))

因此,您将发送{}作为主机名,并将'g‘作为第二个参数传递,这可能就是错误的来源。我不知道你想做什么,但你可能想:

代码语言:javascript
复制
    remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70399001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档