EnumTypeWrapper JSON Issue

To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.

What I want to do

I am having the exact same problem as Python Insert script not working - I get the same error and I have the right version as noted in the original post - but I’m not even sure how to attempt to fix this. I’m using a default Ubuntu to test this all out.

txn = client.txn()

Create data.

p = {
… ‘name’: ‘Alice’,
… }

Run mutation.

Traceback (most recent call last):
File “”, line 1, in
File “/home/dave/.local/lib/python3.8/site-packages/pydgraph/txn.py”, line 75, in mutate
req = self.create_request(mutations=[mutation], commit_now=commit_now)
File “/home/dave/.local/lib/python3.8/site-packages/pydgraph/txn.py”, line 197, in create_request
resp_format = api.Request.RespFormat.JSON
AttributeError: ‘EnumTypeWrapper’ object has no attribute ‘JSON’
Please list the high level idea of what you want to do

What I did

I tried installing protobuf, looking at pip to see if I can find a new one… I have version 21.3.0 (as in the original post). I’m using dgraph from docker (simple little test engine).

Please list the things you have tried.

Dgraph metadata

dgraph version

Dgraph version : v21.03.0
Dgraph codename : rocket
Dgraph SHA-256 : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f
Commit SHA-1 : a77bbe8ae
Commit timestamp : 2021-04-07 21:36:38 +0530

Can you clone the repo and run the tests?

I certainly could clone a repo and do further testing… Do you mean the whole dgraph repo? Or just the pydgraph ?

Just the pydgraph.

I downloaded the latest git from github…clearly I’m doing something wrong though!

dave@dave-VirtualBox:~/pydgraph$ python3
Python 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import pydgraph
Traceback (most recent call last):
File “”, line 1, in
File “/home/dave/pydgraph/pydgraph/init.py”, line 17, in
from pydgraph.client_stub import *
File “/home/dave/pydgraph/pydgraph/client_stub.py”, line 102
“”“Returns Dgraph Client stub for the Slash GraphQL endpoint”""
IndentationError: expected an indented block

A clean virtual environment DOES seem to work though…

I think the default protobuf for Ubuntu is not compatible?

dave@dave-VirtualBox:~$ source ./myenv/bin/activate
(myenv) dave@dave-VirtualBox:~$ pip install pydgraph
Collecting pydgraph
Using cached pydgraph-21.3.0-py2.py3-none-any.whl (26 kB)
Collecting grpcio>=1.18.0
Using cached grpcio-1.38.0-cp38-cp38-manylinux2014_x86_64.whl (4.2 MB)
Collecting protobuf>=3.6.1
Downloading protobuf-3.17.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB)

████████████████████████████████| 1.0 MB 2.5 MB/s
Collecting six>=1.5.2
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, grpcio, protobuf, pydgraph
Successfully installed grpcio-1.38.0 protobuf-3.17.3 pydgraph-21.3.0 six-1.16.0
(myenv) dave@dave-VirtualBox:~$ python3 test.py
(myenv) dave@dave-VirtualBox:~$

Not sure, I use Darwin. I was hoping it was some simple mistake that making the test would guarantee that wasn’t nothing related to the env itself. As the tests are made for Linux env they should run fine. Also I think we use Ubuntu in our TC.

Yeah, someone should re-test this with a normal ubuntu because it’s pretty broken and it’s not clear how to fix it as a beginner…


I cloned the example repo.

ubuntu server 20.04. I’m working remotely with python 3.8 via Juptyer Notebooks. I tried to run the example, this is the error I get:

Still able to alter the schema and query, but cannot mutate.

AttributeError                            Traceback (most recent call last)
<ipython-input-43-f5cae1f9899f> in <module>
     19     # Run mutation.
     20     mu = pydgraph.Mutation(set_json=json.dumps(p).encode('utf8'))
---> 21     response = txn.mutate(mu)
     23     # Commit transaction.

~/.local/lib/python3.8/site-packages/pydgraph/txn.py in mutate(self, mutation, set_obj, del_obj, set_nquads, del_nquads, cond, commit_now, timeout, metadata, credentials)
     73         mutation = self.create_mutation(mutation, set_obj, del_obj, set_nquads, del_nquads, cond)
     74         commit_now = commit_now or mutation.commit_now
---> 75         req = self.create_request(mutations=[mutation], commit_now=commit_now)
     76         return self.do_request(req, timeout=timeout, metadata=metadata, credentials=credentials)

~/.local/lib/python3.8/site-packages/pydgraph/txn.py in create_request(self, query, variables, mutations, commit_now, resp_format)
    195     def create_request(self, query=None, variables=None, mutations=None, commit_now=None, resp_format="JSON"):
    196         if resp_format=="JSON":
--> 197             resp_format = api.Request.RespFormat.JSON
    198         elif resp_format =="RDF":
    199             resp_format = api.Request.RespFormat.RDF

AttributeError: 'EnumTypeWrapper' object has no attribute 'JSON'

So I’m not crazy then? :slight_smile: