mkh*_*tib 5 python google-app-engine google-cloud-endpoints
我开始使用Google Cloud Endpoints,并且在指定多个服务类时遇到了问题.知道如何让这个工作吗?
ApiConfigurationError: Attempting to implement service myservice, version v1, with multiple classes that aren't compatible. See docstring for api() for examples how to implement a multi-class API.
Run Code Online (Sandbox Code Playgroud)
这就是我创建端点服务器的方式.
AVAILABLE_SERVICES = [
FirstService,
SecondService
]
app = endpoints.api_server(AVAILABLE_SERVICES)
Run Code Online (Sandbox Code Playgroud)
对于我正在做的每个服务类:
@endpoints.api(name='myservice', version='v1', description='MyService API')
class FirstService(remote.Service):
...
@endpoints.api(name='myservice', version='v1', description='MyService API')
class SecondService(remote.Service):
...
Run Code Online (Sandbox Code Playgroud)
这些中的每一个都完美地分开工作,但我不确定如何在组合它们时让它们工作.
非常感谢.
正确的方法是创建一个api对象并使用collection
api_root = endpoints.api(name='myservice', version='v1', description='MyService API')
@api_root.collection(resource_name='first')
class FirstService(remote.Service):
...
@api_root.collection(resource_name='second')
class SecondService(remote.Service):
...
Run Code Online (Sandbox Code Playgroud)
其中资源名称将插入方法名称前面,以便您可以使用
@endpoints.method(name='method', ...)
def MyMethod(self, request):
...
Run Code Online (Sandbox Code Playgroud)
代替
@endpoints.method(name='first.method', ...)
def MyMethod(self, request):
...
Run Code Online (Sandbox Code Playgroud)
该api_root对象相当于一个remote.Service装饰的类endpoints.api,因此您只需将其包含在endpoints.api_server列表中即可.例如:
application = endpoints.api_server([api_root, ...])
Run Code Online (Sandbox Code Playgroud)