Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.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 返回GAE协议的HTTP代码_Python_Google App Engine_Protorpc - Fatal编程技术网

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字段指定特定于应用程序的错误条件