Python Insert script not working

Here is the example script that I tried:

test.py:

import pydgraph

client_stub = pydgraph.DgraphClientStub.from_slash_endpoint("https://ancient-lake.us-west-2.aws.cloud.dgraph.io/graphql", <api-key>)
client = pydgraph.DgraphClient(client_stub)
txn = client.txn()
p = {
        'dgraph.type' : 'User',
        'username' : 'KrisR'
}
try:
        txn.mutate(set_obj=p)
        txn.commit()
finally:
        txn.discard()

I get the following error. Can you please help?

  File "dgraphaccess.py", line 11, in <module>
    txn.mutate(set_obj=p) 
  File "/usr/local/lib/python3.8/dist-packages/pydgraph/txn.py", line 75, in mutate
    req = self.create_request(mutations=[mutation], commit_now=commit_now)
  File "/usr/local/lib/python3.8/dist-packages/pydgraph/txn.py", line 197, in create_request
    resp_format = api.Request.RespFormat.JSON
AttributeError: 'EnumTypeWrapper' object has no attribute 'JSON'

Hi @krisraman - welcome to the Dgraph forums! We hope you enjoy the stay.

Can you tell me which version of PyDgraph you are using? I just tried reproducing your code and it works correctly. (mine is pydgraph-21.3.0)

Hi @chewxy , Thanks for looking into my issue. I am running pydgraph 21.3.0 as well.

Kris

Here is the detail

pip show pydgraph

Name: pydgraph
Version: 21.3.0
Summary: Official Dgraph client implementation for Python
Home-page: GitHub - dgraph-io/pydgraph: Official Dgraph Python client
Author: Dgraph Labs
Author-email: contact@dgraph.io
License: Apache License, Version 2.0
Location: /usr/local/lib/python3.8/dist-packages
Requires: protobuf, grpcio
Required-by:

Hi @chewxy , Any update? Is there anything I should check. Am in the process of choosing a graph db and your response would help me with evaluation. Thanks

Kris