Home > OS >  Amazon Neptune on submitting query: AttributeError: 'str' object has no attribute 'so
Amazon Neptune on submitting query: AttributeError: 'str' object has no attribute 'so

Time:12-19

I have the following code running on AWS lambda, but getting the following error.

Error

[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

Source code

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

CodePudding user response:

If you send the query as a text string you need to create the Client object differently or write the query as in-line Python. There are two examples at (1) and (2) that show each option.

Using a DriverRemoteConnection you can use a Python line of code such as:

result = (g.V().groupCount().
                  by(label).
            unfold().
            project('label','count').
              by(keys).
              by(values).
            next())
``

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

CodePudding user response:

Your DriverRemoteConnection call is wrong. You have:

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

So you are sending {} as the hostname, and passing 'g' as a second parameter, which is probably where the error comes from. I don't know what you intended the 'g' for, but you probably want:

    remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host))
  • Related