AppEngine终结点中MessageField的GET请求参数不是

2024-09-28 22:03:11 发布

您现在位置:Python中文网/ 问答频道 /正文

由于某些原因,当使用http_method=GET而不是POST时,我无法读取请求参数。在

@endpoints.method(RequestMessage,
                  ResponseMessage,
                  name='get',
                  path='mypath',
                  http_method='GET')
def get_challenge(self, request):
    # This is None in http_method=GET but works on POST
    print request.my_message_field

我的信息类是这样的:

^{pr2}$

我正在通过API浏览器测试API。知道我做错什么了吗?在

谢谢


Tags: pathnameapihttp参数getrequest原因
1条回答
网友
1楼 · 发布于 2024-09-28 22:03:11

参数应该显示为my_message_field.idmy_message_field.name。在

根本的区别在于GET没有有效载荷,POST有。因此,参数名称空间必须是“flat”而不是嵌套JSON。为了适应这一点,我们把我前面提到的参数展平。在

更新:

这一定是由于某些内容没有正确地移植到devappserver而引起的。我向endpoints.apiserving添加了一个记录器,以确定从API前端传递到应用程序引擎后端的内容:

生产中

'{"my_message_field":{"id":"x","name":"y"}}'

devappserver2

^{pr2}$

尝试通过解析时

from protorpc import remote
protocols = remote.Protocols.get_default()
json_protocol = protocols.lookup_by_content_type('application/json')
json_protocol.decode_message(RequestMessage, payload)

这就是api_server所做的,这就是发生的事情

生产中

<RequestMessage
 my_message_field: <MyMessage
 id: u'x'
 name: u'y'>>

devappserver2

<RequestMessage>

相关问题 更多 >