Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google Cloud Endpoints V2多类API错误应用程序引擎标准_Python_Google App Engine_Google Cloud Endpoints - Fatal编程技术网

Python Google Cloud Endpoints V2多类API错误应用程序引擎标准

Python Google Cloud Endpoints V2多类API错误应用程序引擎标准,python,google-app-engine,google-cloud-endpoints,Python,Google App Engine,Google Cloud Endpoints,错误:ApiConfigurationError:尝试使用多个不兼容的类实现service echo,版本v2。有关如何实现多类api的示例,请参见docstring for api() 代码: import logging import endpoints from protorpc import message_types from protorpc import messages from protorpc import remote class EchoRequest(messages

错误:ApiConfigurationError:尝试使用多个不兼容的类实现service echo,版本v2。有关如何实现多类api的示例,请参见docstring for 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))

@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])
如果只有:version='v1'(EchoApi)就很好

如果添加了:version='v2'时出错(EchoApi2)

错误代码:ApiConfigurationError:尝试使用多个不兼容的类实现service echo,版本v2。有关如何实现多类api的示例,请参见docstring for api()


多谢各位

这是创建使用多个类实现的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])
文件对此进行了解释: