过去几天我一直在使用 Google Cloud Endpoints(旨在将其与 AngularJS 挂钩),当我尝试从我的数据存储中检索单个实体时遇到了一些麻烦。
我的ndb
模型设置是:
class Ingredients(EndpointsModel):
ingredient = ndb.StringProperty()
class Recipe(EndpointsModel):
title = ndb.StringProperty(required=True)
description = ndb.StringProperty(required=True)
ingredients = ndb.StructuredProperty(Ingredients, repeated=True)
instructions = ndb.StringProperty(required=True)
这是我定义的用于检索实体的 API 方法'title'
:
@Recipe.method(request_fields=('title',), path='recipe/{title}',
http_method='GET', name='recipe.get')
def get_recipe(self, recipe):
if not recipe.from_datastore:
raise endpoints.NotFoundException('Recipe not found.')
return recipe
如果我使用'id'
(由 提供的帮助方法EndpointsModel
)代替'title'
请求字段,API 方法可以正常工作。但是,当我使用'title'
时,我得到了
404 未找到
{“error_message”:“找不到配方。”,“state”:“APPLICATION_ERROR”}
谁能指出我是否在某处遗漏了什么?
注意:见评论。用于阅读的问题中的错误
400 错误请求
{“error_message”:“解析 ProtoRPC 请求时出错(无法解析请求内容:消息 RecipeProto_title 缺少必填字段标题)”,“状态”:“REQUEST_ERROR”}
但是@sentiki能够解决这个先前的错误。