Python 返回GAE协议的HTTP代码
如何控制Python 返回GAE协议的HTTP代码,python,google-app-engine,protorpc,Python,Google App Engine,Protorpc,如何控制protoRPC响应中的HTTP状态代码 假设我有以下服务: class ApiService(remote.Service): @remote.method(ApiRequestContextCreate, ApiResponseContextCreate) def context_create(self, request): cid = helpers.create_context(request.name) return ApiRe
protoRPC
响应中的HTTP状态代码
假设我有以下服务:
class ApiService(remote.Service):
@remote.method(ApiRequestContextCreate, ApiResponseContextCreate)
def context_create(self, request):
cid = helpers.create_context(request.name)
return ApiResponseContextCreate(cid=cid)
在我看来,protorpcapi缺乏语义:要么请求可以被满足并返回200
,要么异常被引发为404
。当然,我们可以在RPC方法中创建一个错误响应,但这似乎很困难
更新:我发现我也可以为
400
提出ApplicationError
,HTTP状态代码不是ProtoRPC规范的一部分,因为ProtoRPC旨在支持HTTP之外的协议。因此,它不能具有特定于HTTP的返回代码。相反,通过引发ApplicationError返回错误,使用error_name字段指定特定于应用程序的错误条件