Grakn的Python API客户端加载数据时出现问题

Grakn的Python API客户端加载数据时出现问题,python,vaticle-typedb,vaticle-typeql,knowledge-graph,Python,Vaticle Typedb,Vaticle Typeql,Knowledge Graph,我使用的是Grakn 1.8.1、python 3.6.8、Grakn客户端1.8.1和grpcio 1.24.1 我定义了一个简单的模式(schema.gql)来执行测试: define nome sub attribute, value string; cpf_srfb sub attribute, value string; id_srfb sub attribute, value string; hops_de_contraparte sub attrib

我使用的是Grakn 1.8.1、python 3.6.8、Grakn客户端1.8.1和grpcio 1.24.1

我定义了一个简单的模式(schema.gql)来执行测试:

define

nome sub attribute,
    value string;

cpf_srfb sub attribute,
    value string;

id_srfb sub attribute,
    value string;

hops_de_contraparte sub attribute,
    value string;

pessoa_fisica sub entity,
    has nome,
    has cpf_srfb,
    has id_srfb,
    has hops_de_contraparte;
使用grakn控制台正确加载此方案,键空间称为“srfb”

之后,我创建了一个数据文件(data.sql),其中只包含一个实例:

insert $pf isa pessoa_fisica, has nome "GUSTAVO RIBEIRO SOARES PINTO", has cpf_srfb "***106887**", has id_srfb "***106887**GUSTAVO RIBEIRO SOARES PINTO", has hops_de_contraparte "5";
同样,使用grakn控制台,数据加载工作正常

当我通过控制台加载模式,然后尝试通过python api加载数据时,就会出现问题

我的python脚本只是:

from grakn.client import GraknClient

uri = "localhost:48555"
keyspace = 'srfb'
filepath = 'C:\grakn\grakn_181\data.gql'

with open(filepath, mode='r') as file:
    insert_query = file.read()

with GraknClient(uri) as client:
    with client.session(keyspace) as session:
        with session.transaction().write() as transaction:
            transaction.query(insert_query)
            transaction.commit()
此时,发生了一个我无法纠正的错误:

Traceback (most recent call last):
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 166, in _block_for_next
    response = next(self._response_iterator)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 388, in __next__
    return self._next()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 382, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1603911191.241000000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace.","grpc_status":2}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "teste.py", line 17, in <module>
    transaction.commit()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\client.py", line 160, in commit
    self._tx_service.commit()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\TransactionService.py", line 54, in commit
    self._communicator.single_request(request)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 192, in single_request
    return SingleResolver(self, request).get()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 70, in get
    response = self._communicator._block_for_next(self)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 184, in _block_for_next
    raise self._error
grakn.exception.GraknError.GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1603911191.241000000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace.","grpc_status":2}"
>

 generated from request: iter_req {
  options {
  }
  query_iter_req {
    query: "insert $pf isa pessoa_fisica, has nome \"GUSTAVO RIBEIRO SOARES PINTO\", has cpf_srfb \"***106887**\", has id_srfb \"***106887**GUSTAVO RIBEIRO SOARES PINTO\", has hops_de_contraparte \"5\";"
    options {
    }
  }
}


起初我认为属性的声明有问题,但事实并非如此,因为同一个insert可以通过控制台完美地工作


为了能够使用python api,我可以做些什么?有人对这个有想法吗​​我可能做错了什么?

如果不从文件中读取,而直接设置insert query,是否有效

insert_query ="insert $pf isa pessoa_fisica, has nome \"GUSTAVO RIBEIRO SOARES PINTO\", has cpf_srfb \"***106887**\", has id_srfb \"***106887**GUSTAVO RIBEIRO SOARES PINTO\", has hops_de_contraparte \"5\";"

正如您已经知道的,通过控制台正确加载的所有内容,您并没有做任何明显的错误

此消息:

hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'
是从python客户端访问的键空间没有定义为类型的明确标志。从控制台访问的密钥空间可能与从客户端访问的密钥空间不同。因此,请仔细检查在使用控制台加载模式时,是否使用
-k
参数来提供键空间,例如:
\grakn console-k srfb-f'C:\grakn\grakn_181\schema.gql
,以便它与客户端使用的键空间相匹配


如果失败,请尝试更改所做的查询,以删除
对侧跳数
,查看是否未定义该类型。按照Banjo的建议,首先尝试从Python字符串传递查询。

我清理了键空间,重新启动了所有进程,脚本工作正常。我不知道是什么问题,但问题解决了。谢谢你的帮助,詹姆斯和班卓。

事实上,这是我第一次尝试,但也没有成功。问题不在于对立面的啤酒花。我从查询中删除了这个属性,日志完全相同,但使用了最后一个剩余的属性(id_srfb)。所有属性都发生了这种情况。尽管日志总是出现后一个属性的问题,但似乎根本没有访问键空间。
hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'