Amazon Neptune on submitting query: AttributeError: 'str' object has no attribute 'source_instructions'

461 views Asked by At

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

There are 2 answers

0
Kelvin Lawrence On

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. The error you are seeing is because the server is trying to find Gremlin bytecode in the packet sent but only found a string (which does not have a source_instructions method).

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

If you actually want/need to send the query as a string instead of bytecode, please see my answer to 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
Tim Roberts On

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