2017-01-21 3 views
1

Ошибка: ApiConfigurationError: попытка реализовать служебное эхо версии v2 с несколькими классами, которые несовместимы. См. Docstring для api() для примеров того, как реализовать API с несколькими классами.Google Cloud Endpoints V2 многоуровневая ошибка API App Engine Standard

Код:

import logging 
import endpoints 
from protorpc import message_types 
from protorpc import messages 
from protorpc import remote 

class EchoRequest(messages.Message): 
    content = messages.StringField(1) 

class EchoResponse(messages.Message): 
    content = messages.StringField(1) 

ECHO_RESOURCE = endpoints.ResourceContainer(
    EchoRequest, n=messages.IntegerField(2, default=1)) 

@endpoints.api(name='echo', version='v1',description='description') 
class EchoApi(remote.Service): 

    @endpoints.method(
    # This method takes a ResourceContainer defined above. 
    ECHO_RESOURCE, 
    # This method returns an Echo message. 
    EchoResponse, 
    path='echo', 
    http_method='POST', 
    name='echo') 

    def echo(self, request): 
    logging.info("echo1"+ str(request.content)) 
    output_content = ' '.join([request.content] * request.n) 
    return EchoResponse(content=output_content) 

@endpoints.api(name='echo', version='v2', description='description2') 
class EchoApi2(remote.Service): 

    @endpoints.method(
    # This method takes a ResourceContainer defined above. 
    ECHO_RESOURCE, 
    # This method returns an Echo message. 
    EchoResponse, 
    path='echo', 
    http_method='POST', 
    name='echo') 

    def echo(self, request): 
    logging.info("echo2" + str(request.content)) 
    output_content = ' '.join([request.content] * request.n) 
    return EchoResponse(content=output_content) 

api = endpoints.api_server([EchoApi, EchoApi2]) 

ХОРОШО, если только: версия = 'v1' (EchoApi)

если

ОШИБКА: версия = 'v2' добавляется (EchoApi2)

ERROR CODE : ApiConfigurationError: попытка реализовать служебное эхо, версия v2, с несколькими классами, которые несовместимы. См. Docstring для api() для примеров того, как реализовать API с несколькими классами.

спасибо.

ответ

2

Это правильный формат для создания API реализован с несколькими классами:

import logging 
import endpoints 
from protorpc import message_types 
from protorpc import messages 
from protorpc import remote 

class EchoRequest(messages.Message): 
    content = messages.StringField(1) 

class EchoResponse(messages.Message): 
    content = messages.StringField(1) 

ECHO_RESOURCE = endpoints.ResourceContainer(
    EchoRequest, n=messages.IntegerField(2, default=1)) 

echo_collection = endpoints.api(name='echo', version='v1', description='description') 

@echo_collection.api_class(resource_name='echo1') 
class EchoApi1(remote.Service): 

    @endpoints.method(
    # This method takes a ResourceContainer defined above. 
    ECHO_RESOURCE, 
    # This method returns an Echo message. 
    EchoResponse, 
    path='echo', 
    http_method='POST', 
    name='echo') 

    def echo(self, request): 
    logging.info("echo1"+ str(request.content)) 
    output_content = ' '.join([request.content] * request.n) 
    return EchoResponse(content=output_content) 

@echo_collection.api_class(resource_name='echo2') 
class EchoApi2(remote.Service): 

    @endpoints.method(
    # This method takes a ResourceContainer defined above. 
    ECHO_RESOURCE, 
    # This method returns an Echo message. 
    EchoResponse, 
    path='echo', 
    http_method='POST', 
    name='echo') 

    def echo(self, request): 
    logging.info("echo2" + str(request.content)) 
    output_content = ' '.join([request.content] * request.n) 
    return EchoResponse(content=output_content) 

api = endpoints.api_server([echo_collection]) 

Документация объясняет это: https://cloud.google.com/endpoints/docs/frameworks/python/create_api#creating_an_api_implemented_with_multiple_classes

Смежные вопросы