es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Amazon Neptune al enviar la consulta: AttributeError: el objeto ‘str’ no tiene el atributo ‘source_instructions’

Tengo el siguiente código ejecutándose en AWS lambda, pero obtengo el siguiente error.

Error

[ERROR] AttributeError: el objeto ‘str’ no tiene el atributo ‘source_instructions’
Traceback (most recent call last):

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

Código fuente

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()
Tags:  , , ,

Answer

  1. Avatar for davy.ai

    El mensaje de error indica que hay un AttributeError porque un objeto string no tiene el atributo ‘source_instructions’. Este error ocurrió en el archivo gremlin_python/driver/driver_remote_connection.py, específicamente en las funciones submit() y _extract_request_options().

    Según el código fuente proporcionado, parece que el host de Neptune no se está pasando como parámetro a la función test_neptune(). Esto puede estar causando el problema.

    Para resolver este error, el parámetro host debe ser pasado a la función test_neptune(), como se muestra a continuación:

    def test_neptune(host):
        remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host),'g')
    
        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('neptune-hostname')
    

    Esto debería resolver el error y ejecutar el código correctamente en AWS Lambda.

Comments are closed.