我正在尝试学习grpc的基础知识,但使用这个应用程序文档中的示例会导致下面显示的错误。我在Mac上使用Python 2.7.11,在一个全新的虚拟主机上。
当使用最新版本的protorpc和six时,我会得到一个错误,当将six降级为其他人在搜索这个问题时建议的1.10.0版本时,我会得到一个不同的错误。这两个错误如下所示。
hello.py文件的内容(直接从文档复制)
from protorpc import messages
from protorpc import remote
from protorpc.wsgi import service
package = 'hello'
class HelloRequest(messages.Message):
my_name = messages.StringField(1, required=True)
class HelloResponse(messages.Message):
hello = messages.StringField(1, required=True)
class HelloService(remote.Service):
@remote.method(HelloRequest, HelloResponse)
def hello(self, request):
return HelloResponse(hello='Hello there, %s!' % request.my_name)
# Map the RPC service and path (/hello)
app = service.service_mappings([('/hello.*', HelloService)])运行最新pip模块的(如下所示版本):
$ pip freeze
protorpc==0.11.1
six==1.11.0
$ python hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
from protorpc import messages
File "/tmp/grpc/lib/python2.7/site-packages/protorpc/messages.py", line 1146, in <module>
class Field(six.with_metaclass(_FieldMeta, object)):
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases使用降级six 模块运行的(版本如下所示):
$ pip freeze
protorpc==0.11.1
six==1.10.0
$ python hello.py
Traceback (most recent call last):
File "hello.py", line 2, in <module>
from protorpc import remote
File "/tmp/grpc/lib/python2.7/site-packages/protorpc/remote.py", line 117, in <module>
from . import protobuf
File "/tmp/grpc/lib/python2.7/site-packages/protorpc/protobuf.py", line 41, in <module>
from .google_imports import ProtocolBuffer
ImportError: cannot import name ProtocolBuffer有一个神奇的组合版本将使这个例子工作,或者如果有可能是我所跟随的文档是过时的和错误的?
谢谢您的建议。
发布于 2017-11-01 22:21:11
这确实是坏的;补丁在里面了,我刚刚发布了补丁的0.12.0。
https://stackoverflow.com/questions/47002725
复制相似问题