grpc報錯問題集合(二)
grpc坑2:
報錯:
(venv) D:\pythonworkspace\rpcTestDemo\server>python main.py
Traceback (most recent call last):
File "main.py", line 5, in <module>
from example import data_pb2, data_pb2_grpc
ModuleNotFoundError: No module named 'example'
而明明是有example包的
最後發現問題,是執行路徑不對,example在main外面,所以解決方案是,把main和mian2取出來,放在example外面。
問題解決。
之後再次報錯
(venv) D:\pythonworkspace\rpcTestDemo>python main.py
Traceback (most recent call last):
File "main.py", line 5, in <module>
from example import data_pb2, data_pb2_grpc
File "D:\pythonworkspace\rpcTestDemo\example\data_pb2_grpc.py", line 4, in <module>
import data_pb2 as data__pb2
ModuleNotFoundError: No module named 'data_pb2'
發現問題是相容性的問題,
在data_pb2_grpc.py中的句子:
import data_pb2 as data_pb2前加上from .
如下圖:
隨後執行成功:
(venv) D:\pythonworkspace\rpcTestDemo>python main.py
(venv) D:\pythonworkspace\rpcTestDemo>python main2.py
received: HELLO,WORLD!