我一直在使用endpoints_proto_datastore
库来构建我的端点API,并且我试图找出如何返回我从搜索API中检索到的记录结果列表。
@query_method似乎需要返回一个Query类型,并且它会在内部进行提取调用。我将如何实现一个可以处理全文搜索的端点方法?我是否只定义了一个自定义protorpc requets Message和response Message并一起跳过endpoints_proto_datastore库?
这是我尝试过的,并且列表没有ToMessage属性的错误。
Encountered unexpected error from ProtoRPC method implementation: AttributeError ('list' object has no attribute 'ToMessage')
Traceback (most recent call last):
File "google_appengine/lib/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
response = method(instance, request)
File "google_appengine/lib/endpoints-1.0/endpoints/api_config.py", line 1329, in invoke_remote
return remote_method(service_instance, request)
File "google_appengine/lib/protorpc-1.0/protorpc/remote.py", line 412, in invoke_remote_method
response = method(service_instance, request)
File "third_party/py/endpoints_proto_datastore/ndb/model.py", line 1416, in EntityToRequestMethod
response = response.ToMessage(fields=response_fields)
AttributeError: 'list' object has no attribute 'ToMessage'
以下是代码的一般视图:
class MyModel(EndpointsModel):
SearchSchema = MessageFieldsSchema(('q',))
_query_string = None
def QueryStringSet_(self, value):
self._query_string = value
@EndpointsAliasProperty(name='q', setter=QueryStringSet_)
def query_string(self):
return self._query_string
class MyServices(...):
@MyModel.method(
request_fields=MyModel.SearchSchema,
name='search', path='mymodel/search')
def SearchMyModel(self, request):
return MyModel.Search(request.q)
答案 0 :(得分:0)
如果您使用的是Java,那么答案就是使用
import com.google.api.server.spi.response.CollectionResponse;
在python中,您需要创建Response Message Classes。