我在AWS上运行了下面的代码,但是得到了以下错误。
错误
[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源代码
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()发布于 2021-12-19 00:28:05
如果以文本字符串的形式发送查询,则需要以不同的方式创建Client对象,或者将查询写成一行Python。在(1)和(2)处有两个示例显示每个选项。您所看到的错误是因为服务器试图在发送的数据包中找到Gremlin字节码,但只找到一个字符串(该字符串没有source_instructions方法)。
使用DriverRemoteConnection,您可以使用Python代码行,如:
result = (g.V().groupCount().
by(label).
unfold().
project('label','count').
by(keys).
by(values).
next())如果您确实希望/需要将查询发送为字符串而不是字节码,请参阅我对this question的答复。
发布于 2021-12-19 00:29:41
你的DriverRemoteConnection电话错了。你有:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))因此,您将发送{}作为主机名,并将'g‘作为第二个参数传递,这可能就是错误的来源。我不知道你想做什么,但你可能想:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host))https://stackoverflow.com/questions/70399001
复制相似问题