问题描述
File "async_greeter_client.py", line 25, in run
async with grpc.aio.insecure_channel('localhost:50051') as channel:
AttributeError: module 'grpc' has no attribute 'aio'
import logging
import asyncio
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
async def run() -> None:
async with grpc.aio.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = await stub.SayHello(helloworld_pb2.HelloRequest(name='you'),timeout=5)
print("Greeter client received: " + response.message)
if __name__ == '__main__':
logging.basicConfig()
#asyncio.run(run())
asyncio.get_event_loop().run_until_complete(run())
原因:我的环境是python3.6