0

I am trying to do a connection through grpc using:

import grpc
import class


def main():
    channel = grpc.insecure_channel('localhost:50051')
    stub = class_pb2_grpc.ClassStub(channel=channel)
    list_data(stub)


if __name__ == '__main__':
    main()

I get:

channel = grpc.insecure_channel('localhost:50051')
AttributeError: module 'grpc' has no attribute 'insecure_channel'

I am running this code in a docker with python 3.8.10 and this packages installed:

protobuf==3.18.0
grpcio==1.41.0
grpcio-tools==1.41.0

EDIT Also tried under grpc.aio using:

channel = grpc.aio.insecure_channel('localhost:50051')

And it returns:

AttributeError: module 'grpc' has no attribute 'aio'
hmn Falahi
  • 730
  • 5
  • 22
mrc
  • 2,845
  • 8
  • 39
  • 73
  • The [documentation](https://grpc.github.io/grpc/python/grpc_asyncio.html#create-channel) has the function under `grpc.aio`, have you tried that? – Jan Wilamowski Sep 28 '21 at 09:20
  • @JanWilamowski yes, it returns `AttributeError: module 'grpc' has no attribute 'aio'` – mrc Sep 28 '21 at 09:21
  • very strange, since it's clearly part of the Python code: https://github.com/grpc/grpc/blob/master/src/python/grpcio/grpc/__init__.py#L2156 – Jan Wilamowski Sep 28 '21 at 09:29
  • @JanWilamowski yes, the same happens for secure channel under aio, or without aio :S – mrc Sep 28 '21 at 09:38
  • My point was, perhaps your Docker container doesn't actually have to correct code installed. Have you double-checked whether the package is installed correctly and is accessible in Python, e.g. by printing `dir(grpc)`? – Jan Wilamowski Sep 28 '21 at 09:39
  • 2
    @JanWilamowski Thanks for the suggest. I just found what happens. We have a test file caled grpc in the root directory. I renamed it as it was some old test and its finding the correct code. Thanks for the help! – mrc Sep 28 '21 at 09:53
  • 1
    Thanks for the tips, it worked here also ! – Oscar May 31 '22 at 15:48

0 Answers0