跳至内容
菜单
此问题已终结

I've defined an @http.route method which receives parameters from a third party. I'm trying to access the body parameters of the request, but I can only access them if they come inside a `params` object. 

For example, I have:

@http.route(['/callback'], type='json', auth="public", csrf=False)
def handler(self, topic=None, **kw ):


and i can only access the `topic` params if in the request it was:

{ "params": {"topic": "foo"} }        


but the third party is doing the request like:

{ "topic": "foo" }        

which I'm unable to fetch. I've tried logging the contents of `**kw` but it logs {}

Thanks

形象
丢弃
编写者

Hey Jack, thanks a lot that was precisely what i needed, sorry I don't have enough karma to comment, upvote or accept the answer :(

最佳答案

Hello Bernado, 

You can use the odoo.http.request lib to grab your post data. 

An example would be:

from odoo import http
from odoo.http import request

class Test(http.Controller):
    @http.route("/test/test/", auth="public", type="json")
    def test_func(self, **kwargs):
        # POST data
        response = request.jsonrequest

Then you can get specific response data using response["topic"]. 

I hope this helps, 

Thanks, 

形象
丢弃
相关帖文 回复 查看 活动
4
6月 24
2355
0
2月 18
4417
2
1月 17
19319
1
11月 22
2867
2
4月 16
4441