Stuck with "module 'grpc' has no attribute '_channel'"

Hi thanks for dgraph, looks very exciting! I am struggling to get a python client to work at all though, any support would be greatly appreciated.

I am having this issue when trying to run a very simple “set” operation using pydgraph:

/opt/conda/lib/python3.8/site-packages/pydgraph/util.py in is_aborted_error(error)
     38 def is_aborted_error(error):
     39     """Returns true if the error is due to an aborted transaction."""
---> 40     if isinstance(error, grpc._channel._Rendezvous) or \
     41        isinstance(error, grpc._channel._InactiveRpcError):
     42         status_code = error.code()

AttributeError: module 'grpc' has no attribute '_channel'

It isn’t clear to me what is happening here. Would anybody be able to throw some light onto this?

Here’s what I tried:

Seeing that it was grpc related I tried reinstalling grpc as indicated in the readme: pip install grpcio==1.19.0 but this also fails with the following cryptic error message:

src/core/lib/gpr/log_linux.cc:43:13: error: ambiguating new declaration of ‘long int gettid()’
       43 | static long gettid(void) { return syscall(__NR_gettid); }
          |             ^~~~~~
    In file included from /usr/include/unistd.h:1170,
                     from src/core/lib/gpr/log_linux.cc:41:
    /usr/include/x86_64-linux-gnu/bits/unistd_ext.h:34:16: note: old declaration ‘__pid_t gettid()’
       34 | extern __pid_t gettid (void) __THROW;
          |                ^~~~~~
    src/core/lib/gpr/log_linux.cc:43:13: warning: ‘long int gettid()’ defined but not used [-Wunused-function]
       43 | static long gettid(void) { return syscall(__NR_gettid); }
          |             ^~~~~~
    creating tmp/tmpre78jfvk
    gcc -pthread -B /opt/conda/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/include/python3.8 -c /tmp/tmpre78jfvk/a.c -o tmp/tmpre78jfvk/a.o
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/distutils/unixccompiler.py", line 117, in _compile
        self.spawn(compiler_so + cc_args + [src, '-o', obj] +
      File "/tmp/pip-install-odd_ek9k/grpcio/src/python/grpcio/_spawn_patch.py", line 54, in _commandfile_spawn
        _classic_spawn(self, command)
      File "/opt/conda/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "/opt/conda/lib/python3.8/distutils/spawn.py", line 36, in spawn
        _spawn_posix(cmd, search_path, dry_run=dry_run)
      File "/opt/conda/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
        raise DistutilsExecError(
    distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/tmp/pip-install-odd_ek9k/grpcio/src/python/grpcio/commands.py", line 272, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "/opt/conda/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
        _build_ext.build_ext.build_extensions(self)
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
        self._build_extensions_serial()
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
        self.build_extension(ext)
      File "/opt/conda/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 196, in build_extension
        _build_ext.build_extension(self, ext)
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
        objects = self.compiler.compile(sources,
      File "/opt/conda/lib/python3.8/distutils/ccompiler.py", line 574, in compile
        self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
      File "/opt/conda/lib/python3.8/distutils/unixccompiler.py", line 120, in _compile
        raise CompileError(msg)
    distutils.errors.CompileError: command 'gcc' failed with exit status 1
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-odd_ek9k/grpcio/setup.py", line 353, in <module>
        setuptools.setup(
      File "/opt/conda/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/opt/conda/lib/python3.8/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/opt/conda/lib/python3.8/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/opt/conda/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/opt/conda/lib/python3.8/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/opt/conda/lib/python3.8/distutils/command/install.py", line 545, in run
        self.run_command('build')
      File "/opt/conda/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/opt/conda/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/opt/conda/lib/python3.8/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/opt/conda/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/opt/conda/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/opt/conda/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 79, in run
        _build_ext.run(self)
      File "/opt/conda/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
        _build_ext.build_ext.run(self)
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 340, in run
        self.build_extensions()
      File "/tmp/pip-install-odd_ek9k/grpcio/src/python/grpcio/commands.py", line 276, in build_extensions
        raise CommandError(
    commands.CommandError: Failed `build_ext` step:
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/distutils/unixccompiler.py", line 117, in _compile
        self.spawn(compiler_so + cc_args + [src, '-o', obj] +
      File "/tmp/pip-install-odd_ek9k/grpcio/src/python/grpcio/_spawn_patch.py", line 54, in _commandfile_spawn
        _classic_spawn(self, command)
      File "/opt/conda/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "/opt/conda/lib/python3.8/distutils/spawn.py", line 36, in spawn
        _spawn_posix(cmd, search_path, dry_run=dry_run)
      File "/opt/conda/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
        raise DistutilsExecError(
    distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/tmp/pip-install-odd_ek9k/grpcio/src/python/grpcio/commands.py", line 272, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "/opt/conda/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
        _build_ext.build_ext.build_extensions(self)
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
        self._build_extensions_serial()
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
        self.build_extension(ext)
      File "/opt/conda/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 196, in build_extension
        _build_ext.build_extension(self, ext)
      File "/opt/conda/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
        objects = self.compiler.compile(sources,
      File "/opt/conda/lib/python3.8/distutils/ccompiler.py", line 574, in compile
        self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
      File "/opt/conda/lib/python3.8/distutils/unixccompiler.py", line 120, in _compile
        raise CompileError(msg)
    distutils.errors.CompileError: command 'gcc' failed with exit status 1
    
    ----------------------------------------
  Rolling back uninstall of grpcio
  Moving to /opt/conda/lib/python3.8/site-packages/grpc/
   from /opt/conda/lib/python3.8/site-packages/~rpc
  Moving to /opt/conda/lib/python3.8/site-packages/grpcio-1.32.0.dist-info/
   from /opt/conda/lib/python3.8/site-packages/~rpcio-1.32.0.dist-info
ERROR: Command errored out with exit status 1: /opt/conda/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-odd_ek9k/grpcio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-odd_ek9k/grpcio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3_02bkqu/install-record.txt --single-version-externally-managed --compile --install-headers /opt/conda/include/python3.8/grpcio Check the logs for full command output.

Here’s some information on my setup:

$ pip --version
pip 20.2.4 from /opt/conda/lib/python3.8/site-packages/pip (python 3.8)

$ python --version
Python 3.8.5

$ pip list | grep grpcio
grpcio                        1.32.0

$ cat /etc/issue
Ubuntu 20.04.1 LTS \n \l 

Running against a server running a dgraph v1.2.2 container.

>> import pydgraph
>> print(pydgraph.VERSION)
20.07.0

Any help will be greatly appreciated.

Welcome Luis!
This contains an example as well as instructions in getting started with a simple python example. Please give it a try and let us know how it goes.

HI Anand,

Thanks for your prompt reply.

I did just that, I copied and pasted the code you suggested and I only changed the endpoint to point to my DGraph server, running the script resulted in this error message:

Error: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses"
	debug_error_string = "{"created":"@1604315134.099693809","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4133,"referenced_errors":[{"created":"@1604315134.099685312","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":397,"grpc_status":14}]}"
>

I am running on the same setup as the original post.

Hi Anand,

I tried that same script again but this time I pointed it to a managed dgraph instance in your servers (thinking that perhaps mine could be too old) and I get this error:

Error: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "DNS resolution failed for service: rare-example.eu-central-1.aws.cloud.dgraph.io/graphql"
	debug_error_string = "{"created":"@1604315458.564269623","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":214,"referenced_errors":[{"created":"@1604315458.564265463","description":"DNS resolution failed for service: rare-example.eu-central-1.aws.cloud.dgraph.io/graphql","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":377,"grpc_status":14,"referenced_errors":[{"created":"@1604315458.564192965","description":"C-ares status is not ARES_SUCCESS qtype=A name=rare-example.eu-central-1.aws.cloud.dgraph.io/graphql is_balancer=0: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":287}]}]}"
>

Seems to happen deep in grpc complains about DNS not resolving but I can visit the address just fine from my browser, so I am not sure what is going on. I really do not know what else to do, I am really stuck here and can’t make any progress with dgraph. Any help would be greatly appreciated.

Hi Luis, Instead of “rare-example.eu-central-1.aws.cloud.dgraph.io/graphql”, please try “rare-example.grpc.eu-central-1.aws.cloud.dgraph.io:443” as the grpc endpoint.

Hi Anand,

Ok, I did one more thing. I tried the simple example, step by step with a docker container in my development machine. I followed the advice here: pydgraph/README.md at master · dgraph-io/pydgraph · GitHub

I created the containers in my dev machine, created the script to whitelist the IPs of the docker containers. Run everything and I got the following results:

$ ./whitelist.sh 
Creating network "simple_default" with the default driver
Creating simple_zero_1   ... done
Creating simple_server_1 ... done

$ python simple.py 
Error: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses"
	debug_error_string = "{"created":"@1604320673.826768605","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4165,"referenced_errors":[{"created":"@1604320673.826764821","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":397,"grpc_status":14}]}"
>

Seeing as I get the same frustrating error in my main dev environment as I got above in my container, I installed grpcio==1.19.0 as suggested in the documentation. The error message then become something else:

$ python simple.py          
Error: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "Connect Failed"
	debug_error_string = "{"created":"@1604320747.902257289","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2267,"referenced_errors":[{"created":"@1604320747.902253585","description":"Pick Cancelled","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":242,"referenced_errors":[{"created":"@1604320747.902235551","description":"Connect Failed","file":"src/core/ext/filters/client_channel/subchannel.cc","file_line":962,"grpc_status":14,"referenced_errors":[{"created":"@1604320747.902225545","description":"Failed to connect to remote host: Connection refused","errno":111,"file":"src/core/lib/iomgr/tcp_client_posix.cc","file_line":207,"os_error":"Connection refused","syscall":"connect","target_address":"ipv4:127.0.0.1:9080"}]}]}]}"

So now I am really at the end of the road, as nothing I have tried seems to get me off the ground. I wish there was a step by step starter guide that could give reproducible results. I am in the process of evaluating dgraph for a project and it looks great and I am very grateful for it. However getting this most basic example to work is proving very challenging.

Hi Luis, We are in the process of improving our documentation. Please bear with us, I apologise for the inconvenience.

First, let us start a simple docker container. Please try this.

docker run --rm -it -p 8000:8000 -p 8080:8080 -p 9080:9080 dgraph/standalone:latest

Next, please confirm that you are able to see the Ratel UI at http://localhost:8000 . If you are able to connect using the defaults, we age good in terms of a basic Dgraph install!

Now you can install the python dependencies and execute the code as mentioned in the python simple example. Please let us know how it goes.

Hi Anand,

Thanks for your patience.

Ok, this seems to have worked:

$ python simple.py 
Created person named "Alice" with uid = 0x2
Number of people named "Alice": 1
Number of people named "Bob": 1
Bob's UID: 0x4
Bob deleted
Number of people named "Alice": 1
Number of people named "Bob": 0
DONE!

Seems like the only real change has been the way to run the container!? I have been using the docker-compose file instead of the method you suggested here? What’s the difference?

The docker-compose.yml file here: https://raw.githubusercontent.com/dgraph-io/dgraph/master/contrib/config/docker/docker-compose.yml seems to refer to an image named dgraph/dgraph, whereas the image you just recommended me to build (and the one that works with the python client) is dgraph/standalone. Would you please elaborate a bit about the difference and why the cryptic grpcio error message?

At a minimum, the Dgraph runtime has 2 processes that need to be started: dgraph zero and dgraph alpha. The docker compose you see is starting these as services. You can consider this as an advanced or detailed setup approach as it will expose a number of additional parameters. It also needs some additional parameters like whitelists, which is not really what one wants to get into while just getting started.

The dgraph/standalone docker image includes the 2 processes mentioned above as well as the Ratel UI for meeting the needs of users who simply want to get started. When we start the standalone image, we want to open the port 8000 (for connecting to ratel), 8080 (for connecting to alpha, required for most use cases) and 9080 (grpc port, for clients like python). Hence those are specified.

Thanks Anand, this helps.

There’s a bunch of stray documentation that appears out of synch with this advice (see Downloads | Dgraph the docker-compose tab) in the dgraph website that doesn’t quite point this out and the grpc error messages are really not developer friendly at all. Oh, well, I guess these are teething problems and will be ironed out as dgraph matures. At least I can continue with the evaluation test case now, thanks!

Thanks a lot for you patient support.

1 Like