Error in my sample code

Moved from GitHub pydgraph/86

Posted by Xls1994:

Hi, I write a simple code like this:

client_stub =pydgraph.DgraphClientStub("spark-1:9082")
client =pydgraph.DgraphClient(client_stub)
txn =client.txn()
p={
    #'uid':'0x12',
    'name':'Tony11',
    'city':'Franch',
}
print p
try:
    assigned = txn.mutate(set_obj=p)
    txn.commit()
finally:
    txn.discard()

client_stub.close()

However I got a error with this code as follows:

Traceback (most recent call last):
  File "dgraphTest.py", line 12, in <module>
    assigned = txn.mutate(set_obj=p)
  File "D:\Program\Anaconda\lib\site-packages\pydgraph\txn.py", line 71, in muta
te
    return self.do_request(req, timeout=timeout, metadata=metadata, credentials=
credentials)
  File "D:\Program\Anaconda\lib\site-packages\pydgraph\txn.py", line 110, in do_
request
    self._common_except_mutate(query_error)
  File "D:\Program\Anaconda\lib\site-packages\pydgraph\txn.py", line 160, in _co
mmon_except_mutate
    raise error
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "Empty query"
        debug_error_string = "{"created":"@1568282122.945000000","description":"
Error received from peer ipv4:10.18.216.230:9082","file":"src/core/lib/surface/c
all.cc","file_line":1052,"grpc_message":"Empty query","grpc_status":2}"

the version of pydgraph is 2.0.2.
the version of Dgraph is v1.0.16
I could not understand what/s wrong with my code, please help me. Thanks!

martinmr commented :

Can you try version 1.2 of pydgraph? Versions >2 have an API change that makes it incompatible with the 1.0.x Dgraph series.

martinmr commented :

I’ll update the readme to include this information

Xls1994 commented :

Thanks, the 1.2 version is right to write data to dgraph.